Merged in update-delete (pull request #58)

This commit is contained in:
RobAtticus NA 2017-01-26 20:19:49 +00:00
commit ee2d914d34
12 changed files with 159 additions and 24 deletions

View File

@ -83,8 +83,8 @@ INSERT INTO conditions(time,device_id,temperature,humidity)
VALUES(NOW(), 'office', 70.0, 50.0);
```
Similarly, querying data is done via normal SQL SELECT commands. Updating
and deleting individual rows is currently _not_ supported.
Similarly, querying data is done via normal SQL SELECT commands.
SQL UPDATE and DELETE commands also work as expected.
### Indexing data

View File

@ -2,15 +2,17 @@
-- well as triggers for newly created hypertables.
-- Trigger to prevent unsupported operations on the main table.
-- Our C code should rewrite a DELETE or UPDATE to apply to the replica and not main table.
-- The only exception is if we use ONLY, which should be an error.
CREATE OR REPLACE FUNCTION _iobeamdb_internal.on_unsupported_main_table()
RETURNS TRIGGER LANGUAGE PLPGSQL AS
$BODY$
BEGIN
IF TG_OP = 'UPDATE' THEN
RAISE EXCEPTION 'UPDATEs not supported on hypertables'
RAISE EXCEPTION 'UPDATE ONLY not supported on hypertables'
USING ERRCODE = 'IO101';
ELSIF TG_OP = 'DELETE' AND current_setting('io.ignore_delete_in_trigger', true) <> 'true' THEN
RAISE EXCEPTION 'DELETEs not currently supported on hypertables'
RAISE EXCEPTION 'DELETE ONLY not currently supported on hypertables'
USING ERRCODE = 'IO101';
END IF;
RETURN NEW;

View File

@ -0,0 +1,15 @@
\set ON_ERROR_STOP 1
\o /dev/null
\ir include/insert.sql
\o
\set ECHO ALL
\c Test1
SELECT * FROM "testNs";
DELETE FROM "testNs" WHERE series_0 = 1.5;
DELETE FROM "testNs" WHERE series_0 = 100;
SELECT * FROM "testNs";

View File

@ -91,11 +91,11 @@ INSERT INTO "Hypertable_1"(time, "Device_id", temp_c, humidity, sensor_1, sensor
VALUES(1257894000000000000, 'dev1', 30, 70, 1, 2, 3, 100);
--expect error cases
\set ON_ERROR_STOP 0
UPDATE "Hypertable_1" SET time = 0 WHERE TRUE;
psql:include/ddl_ops_1.sql:27: ERROR: IO101: UPDATEs not supported on hypertables
UPDATE ONLY "Hypertable_1" SET time = 0 WHERE TRUE;
psql:include/ddl_ops_1.sql:27: ERROR: IO101: UPDATE ONLY not supported on hypertables
LOCATION: exec_stmt_raise, pl_exec.c:3165
DELETE FROM "Hypertable_1" WHERE "Device_id" = 'dev1';
psql:include/ddl_ops_1.sql:28: ERROR: IO101: DELETEs not currently supported on hypertables
DELETE FROM ONLY "Hypertable_1" WHERE "Device_id" = 'dev1';
psql:include/ddl_ops_1.sql:28: ERROR: IO101: DELETE ONLY not currently supported on hypertables
LOCATION: exec_stmt_raise, pl_exec.c:3165
\set ON_ERROR_STOP 1
SELECT * FROM PUBLIC."Hypertable_1";

View File

@ -72,11 +72,11 @@ INSERT INTO "Hypertable_1"(time, "Device_id", temp_c, humidity, sensor_1, sensor
VALUES(1257894000000000000, 'dev1', 30, 70, 1, 2, 3, 100);
--expect error cases
\set ON_ERROR_STOP 0
UPDATE "Hypertable_1" SET time = 0 WHERE TRUE;
psql:include/ddl_ops_1.sql:27: ERROR: IO101: UPDATEs not supported on hypertables
UPDATE ONLY "Hypertable_1" SET time = 0 WHERE TRUE;
psql:include/ddl_ops_1.sql:27: ERROR: IO101: UPDATE ONLY not supported on hypertables
LOCATION: exec_stmt_raise, pl_exec.c:3165
DELETE FROM "Hypertable_1" WHERE "Device_id" = 'dev1';
psql:include/ddl_ops_1.sql:28: ERROR: IO101: DELETEs not currently supported on hypertables
DELETE FROM ONLY "Hypertable_1" WHERE "Device_id" = 'dev1';
psql:include/ddl_ops_1.sql:28: ERROR: IO101: DELETE ONLY not currently supported on hypertables
LOCATION: exec_stmt_raise, pl_exec.c:3165
\set ON_ERROR_STOP 1
SELECT * FROM PUBLIC."Hypertable_1";

View File

@ -0,0 +1,36 @@
psql:include/create_clustered_db.sql:12: NOTICE: installing required extension "dblink"
psql:include/create_clustered_db.sql:12: NOTICE: installing required extension "postgres_fdw"
psql:include/create_clustered_db.sql:12: NOTICE: installing required extension "hstore"
psql:include/create_clustered_db.sql:16: NOTICE: installing required extension "dblink"
psql:include/create_clustered_db.sql:16: NOTICE: installing required extension "postgres_fdw"
psql:include/create_clustered_db.sql:16: NOTICE: installing required extension "hstore"
psql:include/create_clustered_db.sql:20: NOTICE: installing required extension "dblink"
psql:include/create_clustered_db.sql:20: NOTICE: installing required extension "postgres_fdw"
psql:include/create_clustered_db.sql:20: NOTICE: installing required extension "hstore"
\c Test1
SELECT * FROM "testNs";
timeCustom | device_id | series_0 | series_1 | series_2 | series_bool
---------------------+-----------+----------+----------+----------+-------------
1257894000000000000 | dev1 | 1.5 | 1 | 2 | t
1257894000000000000 | dev1 | 1.5 | 2 | |
1257894000000001000 | dev1 | 2.5 | 3 | |
1257894001000000000 | dev1 | 3.5 | 4 | |
1257897600000000000 | dev1 | 4.5 | 5 | | f
1257894002000000000 | dev1 | 2.5 | 3 | |
1257987600000000000 | dev1 | 1.5 | 1 | |
1257987600000000000 | dev1 | 1.5 | 2 | |
1257894000000000000 | dev20 | 1.5 | 1 | |
1257894000000000000 | dev20 | 1.5 | 2 | |
(10 rows)
DELETE FROM "testNs" WHERE series_0 = 1.5;
DELETE FROM "testNs" WHERE series_0 = 100;
SELECT * FROM "testNs";
timeCustom | device_id | series_0 | series_1 | series_2 | series_bool
---------------------+-----------+----------+----------+----------+-------------
1257894000000001000 | dev1 | 2.5 | 3 | |
1257894001000000000 | dev1 | 3.5 | 4 | |
1257897600000000000 | dev1 | 4.5 | 5 | | f
1257894002000000000 | dev1 | 2.5 | 3 | |
(4 rows)

View File

@ -853,7 +853,7 @@ SELECT * FROM _iobeamdb_catalog.partition_replica;
4 | 4 | 2 | 0 | _iobeamdb_internal | _hyper_2_4_0_partition
(4 rows)
select * from public.chunk_closing_test;
SELECT * FROM chunk_closing_test;
time | metric | device_id
------+--------+-----------
1 | 1 | dev1
@ -861,3 +861,28 @@ select * from public.chunk_closing_test;
3 | 3 | dev3
(3 rows)
SELECT * FROM ONLY chunk_closing_test;
time | metric | device_id
------+--------+-----------
(0 rows)
SELECT * FROM "testNs";
timeCustom | device_id | series_0 | series_1 | series_2 | series_bool
---------------------+-----------+----------+----------+----------+-------------
1257894000000000000 | dev1 | 1.5 | 1 | 2 | t
1257894000000000000 | dev1 | 1.5 | 2 | |
1257894000000001000 | dev1 | 2.5 | 3 | |
1257894001000000000 | dev1 | 3.5 | 4 | |
1257897600000000000 | dev1 | 4.5 | 5 | | f
1257894002000000000 | dev1 | 2.5 | 3 | |
1257987600000000000 | dev1 | 1.5 | 1 | |
1257987600000000000 | dev1 | 1.5 | 2 | |
1257894000000000000 | dev20 | 1.5 | 1 | |
1257894000000000000 | dev20 | 1.5 | 2 | |
(10 rows)
SELECT * FROM ONLY "testNs";
timeCustom | device_id | series_0 | series_1 | series_2 | series_bool
------------+-----------+----------+----------+----------+-------------
(0 rows)

View File

@ -0,0 +1,42 @@
psql:include/create_clustered_db.sql:12: NOTICE: installing required extension "dblink"
psql:include/create_clustered_db.sql:12: NOTICE: installing required extension "postgres_fdw"
psql:include/create_clustered_db.sql:12: NOTICE: installing required extension "hstore"
psql:include/create_clustered_db.sql:16: NOTICE: installing required extension "dblink"
psql:include/create_clustered_db.sql:16: NOTICE: installing required extension "postgres_fdw"
psql:include/create_clustered_db.sql:16: NOTICE: installing required extension "hstore"
psql:include/create_clustered_db.sql:20: NOTICE: installing required extension "dblink"
psql:include/create_clustered_db.sql:20: NOTICE: installing required extension "postgres_fdw"
psql:include/create_clustered_db.sql:20: NOTICE: installing required extension "hstore"
\c Test1
SELECT * FROM "testNs";
timeCustom | device_id | series_0 | series_1 | series_2 | series_bool
---------------------+-----------+----------+----------+----------+-------------
1257894000000000000 | dev1 | 1.5 | 1 | 2 | t
1257894000000000000 | dev1 | 1.5 | 2 | |
1257894000000001000 | dev1 | 2.5 | 3 | |
1257894001000000000 | dev1 | 3.5 | 4 | |
1257897600000000000 | dev1 | 4.5 | 5 | | f
1257894002000000000 | dev1 | 2.5 | 3 | |
1257987600000000000 | dev1 | 1.5 | 1 | |
1257987600000000000 | dev1 | 1.5 | 2 | |
1257894000000000000 | dev20 | 1.5 | 1 | |
1257894000000000000 | dev20 | 1.5 | 2 | |
(10 rows)
UPDATE "testNs" SET series_1 = 47;
UPDATE "testNs" SET series_bool = true;
SELECT * FROM "testNs";
timeCustom | device_id | series_0 | series_1 | series_2 | series_bool
---------------------+-----------+----------+----------+----------+-------------
1257894000000000000 | dev1 | 1.5 | 47 | 2 | t
1257894000000000000 | dev1 | 1.5 | 47 | | t
1257894000000001000 | dev1 | 2.5 | 47 | | t
1257894001000000000 | dev1 | 3.5 | 47 | | t
1257897600000000000 | dev1 | 4.5 | 47 | | t
1257894002000000000 | dev1 | 2.5 | 47 | | t
1257987600000000000 | dev1 | 1.5 | 47 | | t
1257987600000000000 | dev1 | 1.5 | 47 | | t
1257894000000000000 | dev20 | 1.5 | 47 | | t
1257894000000000000 | dev20 | 1.5 | 47 | | t
(10 rows)

View File

@ -24,6 +24,6 @@ INSERT INTO "Hypertable_1"(time, "Device_id", temp_c, humidity, sensor_1, sensor
VALUES(1257894000000000000, 'dev1', 30, 70, 1, 2, 3, 100);
--expect error cases
\set ON_ERROR_STOP 0
UPDATE "Hypertable_1" SET time = 0 WHERE TRUE;
DELETE FROM "Hypertable_1" WHERE "Device_id" = 'dev1';
UPDATE ONLY "Hypertable_1" SET time = 0 WHERE TRUE;
DELETE FROM ONLY "Hypertable_1" WHERE "Device_id" = 'dev1';
\set ON_ERROR_STOP 1

View File

@ -15,4 +15,7 @@ FROM "_iobeamdb_internal"._hyper_1_0_distinct;
SELECT * FROM _iobeamdb_catalog.chunk;
SELECT * FROM _iobeamdb_catalog.chunk_replica_node;
SELECT * FROM _iobeamdb_catalog.partition_replica;
select * from public.chunk_closing_test;
SELECT * FROM chunk_closing_test;
SELECT * FROM ONLY chunk_closing_test;
SELECT * FROM "testNs";
SELECT * FROM ONLY "testNs";

View File

@ -0,0 +1,15 @@
\set ON_ERROR_STOP 1
\o /dev/null
\ir include/insert.sql
\o
\set ECHO ALL
\c Test1
SELECT * FROM "testNs";
UPDATE "testNs" SET series_1 = 47;
UPDATE "testNs" SET series_bool = true;
SELECT * FROM "testNs";

View File

@ -113,8 +113,6 @@ iobeamdb_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
/* replace call to main table with call to the replica table */
if (parse->commandType == CMD_SELECT)
{
change_table_name_context context;
context.hypertable_info = NIL;
change_table_name_walker((Node *) parse, &context);
@ -122,7 +120,6 @@ iobeamdb_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
{
add_partitioning_func_qual(parse, context.hypertable_info);
}
}
if (printParse != NULL && strcmp(printParse, "true") == 0)
{