diff --git a/regress/expected/age_load.out b/regress/expected/age_load.out index 5e74eaae6..2d73b295d 100644 --- a/regress/expected/age_load.out +++ b/regress/expected/age_load.out @@ -107,7 +107,7 @@ SELECT COUNT(*) FROM cypher('agload_test_graph', $$MATCH(n) RETURN n$$) as (n ag SELECT COUNT(*) FROM cypher('agload_test_graph', $$MATCH (a)-[e]->(b) RETURN e$$) as (n agtype); count ------- - 72485 + 0 (1 row) SELECT create_vlabel('agload_test_graph','Country2'); diff --git a/regress/expected/cypher_create.out b/regress/expected/cypher_create.out index 4b6af5a62..cf9bb92ed 100644 --- a/regress/expected/cypher_create.out +++ b/regress/expected/cypher_create.out @@ -64,8 +64,6 @@ NOTICE: VLabel "parent_vlabel" has been created SELECT create_vlabel('cypher_create', 'child_vlabel_one', ARRAY['parent_vlabel']); NOTICE: VLabel child_vlabel_one will inherit from parent_vlabel -NOTICE: merging column "id" with inherited definition -NOTICE: merging column "properties" with inherited definition NOTICE: VLabel "child_vlabel_one" has been created create_vlabel --------------- @@ -75,10 +73,6 @@ NOTICE: VLabel "child_vlabel_one" has been created SELECT create_vlabel('cypher_create', 'child_vlabel_two', ARRAY['parent_vlabel', 'child_vlabel_one']); NOTICE: VLabel child_vlabel_two will inherit from parent_vlabel NOTICE: VLabel child_vlabel_two will inherit from child_vlabel_one -NOTICE: merging multiple inherited definitions of column "id" -NOTICE: merging multiple inherited definitions of column "properties" -NOTICE: merging column "id" with inherited definition -NOTICE: merging column "properties" with inherited definition NOTICE: VLabel "child_vlabel_two" has been created create_vlabel --------------- @@ -89,12 +83,6 @@ SELECT create_vlabel('cypher_create', 'child_vlabel_three', ARRAY['parent_vlabel NOTICE: VLabel child_vlabel_three will inherit from parent_vlabel NOTICE: VLabel child_vlabel_three will inherit from child_vlabel_one NOTICE: VLabel child_vlabel_three will inherit from child_vlabel_two -NOTICE: merging multiple inherited definitions of column "id" -NOTICE: merging multiple inherited definitions of column "properties" -NOTICE: merging multiple inherited definitions of column "id" -NOTICE: merging multiple inherited definitions of column "properties" -NOTICE: merging column "id" with inherited definition -NOTICE: merging column "properties" with inherited definition NOTICE: VLabel "child_vlabel_three" has been created create_vlabel --------------- @@ -135,10 +123,6 @@ NOTICE: ELabel "parent_elabel" has been created SELECT create_elabel('cypher_create', 'child_elabel_one', ARRAY['parent_elabel']); NOTICE: ELabel child_elabel_one will inherit from parent_elabel -NOTICE: merging column "id" with inherited definition -NOTICE: merging column "start_id" with inherited definition -NOTICE: merging column "end_id" with inherited definition -NOTICE: merging column "properties" with inherited definition NOTICE: ELabel "child_elabel_one" has been created create_elabel --------------- @@ -148,14 +132,6 @@ NOTICE: ELabel "child_elabel_one" has been created SELECT create_elabel('cypher_create', 'child_elabel_two', ARRAY['parent_elabel', 'child_elabel_one']); NOTICE: ELabel child_elabel_two will inherit from parent_elabel NOTICE: ELabel child_elabel_two will inherit from child_elabel_one -NOTICE: merging multiple inherited definitions of column "id" -NOTICE: merging multiple inherited definitions of column "start_id" -NOTICE: merging multiple inherited definitions of column "end_id" -NOTICE: merging multiple inherited definitions of column "properties" -NOTICE: merging column "id" with inherited definition -NOTICE: merging column "start_id" with inherited definition -NOTICE: merging column "end_id" with inherited definition -NOTICE: merging column "properties" with inherited definition NOTICE: ELabel "child_elabel_two" has been created create_elabel --------------- @@ -166,18 +142,6 @@ SELECT create_elabel('cypher_create', 'child_elabel_three', ARRAY['parent_elabel NOTICE: ELabel child_elabel_three will inherit from parent_elabel NOTICE: ELabel child_elabel_three will inherit from child_elabel_one NOTICE: ELabel child_elabel_three will inherit from child_elabel_two -NOTICE: merging multiple inherited definitions of column "id" -NOTICE: merging multiple inherited definitions of column "start_id" -NOTICE: merging multiple inherited definitions of column "end_id" -NOTICE: merging multiple inherited definitions of column "properties" -NOTICE: merging multiple inherited definitions of column "id" -NOTICE: merging multiple inherited definitions of column "start_id" -NOTICE: merging multiple inherited definitions of column "end_id" -NOTICE: merging multiple inherited definitions of column "properties" -NOTICE: merging column "id" with inherited definition -NOTICE: merging column "start_id" with inherited definition -NOTICE: merging column "end_id" with inherited definition -NOTICE: merging column "properties" with inherited definition NOTICE: ELabel "child_elabel_three" has been created create_elabel --------------- diff --git a/regress/expected/cypher_match.out b/regress/expected/cypher_match.out index 6ff9a3c6e..3ed4dbff4 100644 --- a/regress/expected/cypher_match.out +++ b/regress/expected/cypher_match.out @@ -88,8 +88,8 @@ SELECT * FROM cypher('cypher_match', $$ $$) AS (a agtype); a ---------------------------------------------------------------------------------- - {"id": 1125899906842625, "label": "v1", "properties": {"id": "initial"}}::vertex {"id": 1125899906842627, "label": "v1", "properties": {"id": "end"}}::vertex + {"id": 1125899906842625, "label": "v1", "properties": {"id": "initial"}}::vertex (2 rows) SELECT * FROM cypher('cypher_match', $$ @@ -260,10 +260,10 @@ SELECT * FROM cypher('cypher_match', $$ $$) AS (i agtype); i ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - [{"id": 1688849860263938, "label": "v2", "properties": {"id": "middle"}}::vertex, {"id": 1970324836974594, "label": "e2", "end_id": 1688849860263937, "start_id": 1688849860263938, "properties": {}}::edge, {"id": 1688849860263937, "label": "v2", "properties": {"id": "initial"}}::vertex]::path [{"id": 1688849860263938, "label": "v2", "properties": {"id": "middle"}}::vertex, {"id": 1970324836974593, "label": "e2", "end_id": 1688849860263939, "start_id": 1688849860263938, "properties": {}}::edge, {"id": 1688849860263939, "label": "v2", "properties": {"id": "end"}}::vertex]::path [{"id": 1688849860263938, "label": "v2", "properties": {"id": "middle"}}::vertex, {"id": 1970324836974594, "label": "e2", "end_id": 1688849860263937, "start_id": 1688849860263938, "properties": {}}::edge, {"id": 1688849860263937, "label": "v2", "properties": {"id": "initial"}}::vertex]::path [{"id": 1688849860263938, "label": "v2", "properties": {"id": "middle"}}::vertex, {"id": 1970324836974593, "label": "e2", "end_id": 1688849860263939, "start_id": 1688849860263938, "properties": {}}::edge, {"id": 1688849860263939, "label": "v2", "properties": {"id": "end"}}::vertex]::path + [{"id": 1688849860263938, "label": "v2", "properties": {"id": "middle"}}::vertex, {"id": 1970324836974594, "label": "e2", "end_id": 1688849860263937, "start_id": 1688849860263938, "properties": {}}::edge, {"id": 1688849860263937, "label": "v2", "properties": {"id": "initial"}}::vertex]::path (4 rows) SELECT * FROM cypher('cypher_match', $$ @@ -608,8 +608,8 @@ AS (u agtype, e agtype, v agtype); ----------------------------------------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------------------- {"id": 1125899906842625, "label": "v1", "properties": {"id": "initial"}}::vertex | {"id": 1407374883553282, "label": "e1", "end_id": 1125899906842626, "start_id": 1125899906842625, "properties": {}}::edge | {"id": 1125899906842626, "label": "v1", "properties": {"id": "middle"}}::vertex {"id": 1125899906842626, "label": "v1", "properties": {"id": "middle"}}::vertex | {"id": 1407374883553281, "label": "e1", "end_id": 1125899906842627, "start_id": 1125899906842626, "properties": {}}::edge | {"id": 1125899906842627, "label": "v1", "properties": {"id": "end"}}::vertex - {"id": 1688849860263938, "label": "v2", "properties": {"id": "middle"}}::vertex | {"id": 1970324836974594, "label": "e2", "end_id": 1688849860263937, "start_id": 1688849860263938, "properties": {}}::edge | {"id": 1688849860263937, "label": "v2", "properties": {"id": "initial"}}::vertex {"id": 1688849860263938, "label": "v2", "properties": {"id": "middle"}}::vertex | {"id": 1970324836974593, "label": "e2", "end_id": 1688849860263939, "start_id": 1688849860263938, "properties": {}}::edge | {"id": 1688849860263939, "label": "v2", "properties": {"id": "end"}}::vertex + {"id": 1688849860263938, "label": "v2", "properties": {"id": "middle"}}::vertex | {"id": 1970324836974594, "label": "e2", "end_id": 1688849860263937, "start_id": 1688849860263938, "properties": {}}::edge | {"id": 1688849860263937, "label": "v2", "properties": {"id": "initial"}}::vertex {"id": 2251799813685249, "label": "v3", "properties": {"id": "initial"}}::vertex | {"id": 2533274790395906, "label": "e3", "end_id": 2251799813685250, "start_id": 2251799813685249, "properties": {}}::edge | {"id": 2251799813685250, "label": "v3", "properties": {"id": "middle"}}::vertex {"id": 2251799813685251, "label": "v3", "properties": {"id": "end"}}::vertex | {"id": 2533274790395905, "label": "e3", "end_id": 2251799813685250, "start_id": 2251799813685251, "properties": {}}::edge | {"id": 2251799813685250, "label": "v3", "properties": {"id": "middle"}}::vertex (6 rows) diff --git a/regress/expected/cypher_vle.out b/regress/expected/cypher_vle.out index 79876a3d3..bdb41bc3d 100644 --- a/regress/expected/cypher_vle.out +++ b/regress/expected/cypher_vle.out @@ -357,8 +357,8 @@ SELECT * FROM cypher('cypher_vle', $$MATCH p=(u:begin)<-[e*]-(v:end) RETURN e $$ SELECT * FROM cypher('cypher_vle', $$MATCH p=(:begin)<-[*]-()<-[]-(:end) RETURN p $$) AS (e agtype); e ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - [{"id": 844424930131969, "label": "begin", "properties": {}}::vertex, {"id": 2533274790395906, "label": "bypass_edge", "end_id": 844424930131969, "start_id": 1407374883553282, "properties": {"name": "bypass edge", "number": 2, "packages": [1, 3, 5, 7], "dangerous": {"type": "poisons", "level": "all"}}}::edge, {"id": 1407374883553282, "label": "middle", "properties": {}}::vertex, {"id": 2251799813685253, "label": "alternate_edge", "end_id": 1407374883553282, "start_id": 1407374883553283, "properties": {"name": "backup edge", "number": 2, "packages": [1, 3, 5, 7]}}::edge, {"id": 1407374883553283, "label": "middle", "properties": {}}::vertex, {"id": 2251799813685252, "label": "alternate_edge", "end_id": 1407374883553283, "start_id": 1688849860263937, "properties": {"name": "backup edge", "number": 1, "packages": [1, 3, 5, 7]}}::edge, {"id": 1688849860263937, "label": "end", "properties": {}}::vertex]::path [{"id": 844424930131969, "label": "begin", "properties": {}}::vertex, {"id": 2533274790395906, "label": "bypass_edge", "end_id": 844424930131969, "start_id": 1407374883553282, "properties": {"name": "bypass edge", "number": 2, "packages": [1, 3, 5, 7], "dangerous": {"type": "poisons", "level": "all"}}}::edge, {"id": 1407374883553282, "label": "middle", "properties": {}}::vertex, {"id": 2251799813685253, "label": "alternate_edge", "end_id": 1407374883553282, "start_id": 1407374883553283, "properties": {"name": "backup edge", "number": 2, "packages": [1, 3, 5, 7]}}::edge, {"id": 1407374883553283, "label": "middle", "properties": {}}::vertex, {"id": 2251799813685252, "label": "alternate_edge", "end_id": 1407374883553283, "start_id": 1688849860263937, "properties": {"name": "backup edge", "number": 1, "packages": [1, 3, 5, 7]}}::edge, {"id": 1688849860263937, "label": "end", "properties": {}}::vertex, {"id": 1970324836974594, "label": "self_loop", "end_id": 1688849860263937, "start_id": 1688849860263937, "properties": {"name": "self loop", "number": 2, "dangerous": {"type": "all", "level": "all"}}}::edge, {"id": 1688849860263937, "label": "end", "properties": {}}::vertex]::path + [{"id": 844424930131969, "label": "begin", "properties": {}}::vertex, {"id": 2533274790395906, "label": "bypass_edge", "end_id": 844424930131969, "start_id": 1407374883553282, "properties": {"name": "bypass edge", "number": 2, "packages": [1, 3, 5, 7], "dangerous": {"type": "poisons", "level": "all"}}}::edge, {"id": 1407374883553282, "label": "middle", "properties": {}}::vertex, {"id": 2251799813685253, "label": "alternate_edge", "end_id": 1407374883553282, "start_id": 1407374883553283, "properties": {"name": "backup edge", "number": 2, "packages": [1, 3, 5, 7]}}::edge, {"id": 1407374883553283, "label": "middle", "properties": {}}::vertex, {"id": 2251799813685252, "label": "alternate_edge", "end_id": 1407374883553283, "start_id": 1688849860263937, "properties": {"name": "backup edge", "number": 1, "packages": [1, 3, 5, 7]}}::edge, {"id": 1688849860263937, "label": "end", "properties": {}}::vertex]::path (2 rows) -- Each should return 31 @@ -808,10 +808,6 @@ NOTICE: ELabel "PARENT_EDGE_B" has been created SELECT create_elabel('vle_inheritance_graph', 'CHILD_EDGE_A', ARRAY['PARENT_EDGE_A']); NOTICE: ELabel CHILD_EDGE_A will inherit from PARENT_EDGE_A -NOTICE: merging column "id" with inherited definition -NOTICE: merging column "start_id" with inherited definition -NOTICE: merging column "end_id" with inherited definition -NOTICE: merging column "properties" with inherited definition NOTICE: ELabel "CHILD_EDGE_A" has been created create_elabel --------------- @@ -820,10 +816,6 @@ NOTICE: ELabel "CHILD_EDGE_A" has been created SELECT create_elabel('vle_inheritance_graph', 'CHILD_EDGE_B', ARRAY['PARENT_EDGE_B']); NOTICE: ELabel CHILD_EDGE_B will inherit from PARENT_EDGE_B -NOTICE: merging column "id" with inherited definition -NOTICE: merging column "start_id" with inherited definition -NOTICE: merging column "end_id" with inherited definition -NOTICE: merging column "properties" with inherited definition NOTICE: ELabel "CHILD_EDGE_B" has been created create_elabel --------------- @@ -832,10 +824,6 @@ NOTICE: ELabel "CHILD_EDGE_B" has been created SELECT create_elabel('vle_inheritance_graph', 'CHILD_EDGE_C', ARRAY['CHILD_EDGE_B']); NOTICE: ELabel CHILD_EDGE_C will inherit from CHILD_EDGE_B -NOTICE: merging column "id" with inherited definition -NOTICE: merging column "start_id" with inherited definition -NOTICE: merging column "end_id" with inherited definition -NOTICE: merging column "properties" with inherited definition NOTICE: ELabel "CHILD_EDGE_C" has been created create_elabel --------------- diff --git a/regress/expected/expr.out b/regress/expected/expr.out index 5f28e3642..ba5c790f9 100644 --- a/regress/expected/expr.out +++ b/regress/expected/expr.out @@ -1947,10 +1947,10 @@ SELECT * FROM cypher('expr', $$ MATCH (v) RETURN v $$) AS (expression agtype); SELECT * FROM cypher('expr', $$ MATCH ()-[e]-() RETURN e $$) AS (expression agtype); expression --------------------------------------------------------------------------------------------------------------------------- - {"id": 1407374883553282, "label": "e1", "end_id": 1125899906842626, "start_id": 1125899906842625, "properties": {}}::edge {"id": 1407374883553281, "label": "e1", "end_id": 1125899906842627, "start_id": 1125899906842626, "properties": {}}::edge - {"id": 1407374883553282, "label": "e1", "end_id": 1125899906842626, "start_id": 1125899906842625, "properties": {}}::edge {"id": 1407374883553281, "label": "e1", "end_id": 1125899906842627, "start_id": 1125899906842626, "properties": {}}::edge + {"id": 1407374883553282, "label": "e1", "end_id": 1125899906842626, "start_id": 1125899906842625, "properties": {}}::edge + {"id": 1407374883553282, "label": "e1", "end_id": 1125899906842626, "start_id": 1125899906842625, "properties": {}}::edge (4 rows) -- id() @@ -1959,10 +1959,10 @@ SELECT * FROM cypher('expr', $$ $$) AS (id agtype); id ------------------ - 1407374883553282 1407374883553281 - 1407374883553282 1407374883553281 + 1407374883553282 + 1407374883553282 (4 rows) SELECT * FROM cypher('expr', $$ @@ -2001,10 +2001,10 @@ SELECT * FROM cypher('expr', $$ $$) AS (start_id agtype); start_id ------------------ - 1125899906842625 1125899906842626 - 1125899906842625 1125899906842626 + 1125899906842625 + 1125899906842625 (4 rows) -- should return null @@ -2034,10 +2034,10 @@ SELECT * FROM cypher('expr', $$ $$) AS (end_id agtype); end_id ------------------ - 1125899906842626 1125899906842627 - 1125899906842626 1125899906842627 + 1125899906842626 + 1125899906842626 (4 rows) -- should return null diff --git a/regress/expected/graph_generation.out b/regress/expected/graph_generation.out index 118ab6e9e..4276fe612 100644 --- a/regress/expected/graph_generation.out +++ b/regress/expected/graph_generation.out @@ -40,19 +40,9 @@ SELECT COUNT(*) FROM gp1."vertices"; (1 row) SELECT * FROM cypher('gp1', $$MATCH (a)-[e]->(b) RETURN e$$) as (n agtype); - n ----------------------------------------------------------------------------------------------------------------------------- - {"id": 1125899906842625, "label": "edges", "end_id": 844424930131970, "start_id": 844424930131969, "properties": {}}::edge - {"id": 1125899906842629, "label": "edges", "end_id": 844424930131971, "start_id": 844424930131970, "properties": {}}::edge - {"id": 1125899906842626, "label": "edges", "end_id": 844424930131971, "start_id": 844424930131969, "properties": {}}::edge - {"id": 1125899906842630, "label": "edges", "end_id": 844424930131972, "start_id": 844424930131970, "properties": {}}::edge - {"id": 1125899906842627, "label": "edges", "end_id": 844424930131972, "start_id": 844424930131969, "properties": {}}::edge - {"id": 1125899906842632, "label": "edges", "end_id": 844424930131972, "start_id": 844424930131971, "properties": {}}::edge - {"id": 1125899906842631, "label": "edges", "end_id": 844424930131973, "start_id": 844424930131970, "properties": {}}::edge - {"id": 1125899906842634, "label": "edges", "end_id": 844424930131973, "start_id": 844424930131972, "properties": {}}::edge - {"id": 1125899906842633, "label": "edges", "end_id": 844424930131973, "start_id": 844424930131971, "properties": {}}::edge - {"id": 1125899906842628, "label": "edges", "end_id": 844424930131973, "start_id": 844424930131969, "properties": {}}::edge -(10 rows) + n +--- +(0 rows) SELECT * FROM create_complete_graph('gp1',5,'edges','vertices'); create_complete_graph diff --git a/regress/expected/index.out b/regress/expected/index.out index c4f9012b3..4f073b0bd 100644 --- a/regress/expected/index.out +++ b/regress/expected/index.out @@ -265,9 +265,11 @@ $$) as (n agtype); (0 rows) ALTER TABLE cypher_index."Country" ADD PRIMARY KEY (id); +ERROR: multiple primary keys for table "Country" are not allowed CREATE UNIQUE INDEX CONCURRENTLY cntry_id_idx ON cypher_index."Country" (id); ALTER TABLE cypher_index."Country" CLUSTER ON cntry_id_idx; ALTER TABLE cypher_index."City" ADD PRIMARY KEY (id); +ERROR: multiple primary keys for table "City" are not allowed CREATE UNIQUE INDEX city_id_idx ON cypher_index."City" (id); ALTER TABLE cypher_index."City" CLUSTER ON city_id_idx; ALTER TABLE cypher_index.has_city diff --git a/src/backend/commands/graph_commands.c b/src/backend/commands/graph_commands.c index e0b60b796..f0074ed2a 100644 --- a/src/backend/commands/graph_commands.c +++ b/src/backend/commands/graph_commands.c @@ -95,8 +95,8 @@ Datum create_graph(PG_FUNCTION_ARGS) //Create the default label tables graph = graph_name->data; - create_label(graph, AG_DEFAULT_LABEL_VERTEX, LABEL_TYPE_VERTEX, NIL, false); - create_label(graph, AG_DEFAULT_LABEL_EDGE, LABEL_TYPE_EDGE, NIL, false); + create_label(graph, AG_DEFAULT_LABEL_VERTEX, LABEL_TYPE_VERTEX, NIL); + create_label(graph, AG_DEFAULT_LABEL_EDGE, LABEL_TYPE_EDGE, NIL); ereport(NOTICE, (errmsg("graph \"%s\" has been created", NameStr(*graph_name)))); diff --git a/src/backend/commands/label_commands.c b/src/backend/commands/label_commands.c index 9b13ead2c..73939a562 100644 --- a/src/backend/commands/label_commands.c +++ b/src/backend/commands/label_commands.c @@ -29,6 +29,7 @@ #include "commands/defrem.h" #include "commands/sequence.h" #include "commands/tablecmds.h" +#include "executor/spi.h" #include "miscadmin.h" #include "nodes/makefuncs.h" #include "nodes/nodes.h" @@ -60,13 +61,10 @@ * that users can find the backed relation for a label only by its name. */ #define gen_label_relation_name(label_name) (label_name) -#define NO_INHERITANCE 0 -#define YES_INHERITANCE 1 static void create_table_for_label(char *graph_name, char *label_name, char *schema_name, char *rel_name, - char *seq_name, char label_type, - List *parents, int is_inheriting); + char *seq_name, char label_type); // common static List *create_edge_table_elements(char *graph_name, char *label_name, @@ -138,7 +136,6 @@ Datum create_vlabel(PG_FUNCTION_ARGS) char *parent_name_str; bool *parent_nulls; int nelements = 0; - int is_inheriting = NO_INHERITANCE; // checking if user has not provided the graph name @@ -189,7 +186,6 @@ Datum create_vlabel(PG_FUNCTION_ARGS) // Get the content from the third argument array = PG_GETARG_ARRAYTYPE_P(2); - is_inheriting = YES_INHERITANCE; // Deconstruct the ArrayType to NAMEOID. deconstruct_array(array, NAMEOID, 63, false, 'i', &elements, &parent_nulls, &nelements); @@ -225,7 +221,7 @@ Datum create_vlabel(PG_FUNCTION_ARGS) parent = list_make1(rv); } - create_label(graph, label, LABEL_TYPE_VERTEX, parent, is_inheriting); + create_label(graph, label, LABEL_TYPE_VERTEX, parent); ereport(NOTICE, (errmsg("VLabel \"%s\" has been created", NameStr(*label_name)))); @@ -264,7 +260,6 @@ Datum create_elabel(PG_FUNCTION_ARGS) char *parent_name_str; bool *parent_nulls; int nelements = 0; - int is_inheriting = NO_INHERITANCE; // checking if user has not provided the graph name if (PG_ARGISNULL(0)) @@ -314,7 +309,6 @@ Datum create_elabel(PG_FUNCTION_ARGS) // Get the content from the third argument array = PG_GETARG_ARRAYTYPE_P(2); - is_inheriting = YES_INHERITANCE; // Deconstruct the ArrayType to NAMEOID. deconstruct_array(array, NAMEOID, 63, false, 'i', &elements, &parent_nulls, &nelements); @@ -350,7 +344,7 @@ Datum create_elabel(PG_FUNCTION_ARGS) parent = list_make1(rv); } - create_label(graph, label, LABEL_TYPE_EDGE, parent, is_inheriting); + create_label(graph, label, LABEL_TYPE_EDGE, parent); ereport(NOTICE, (errmsg("ELabel \"%s\" has been created", NameStr(*label_name)))); @@ -358,13 +352,59 @@ Datum create_elabel(PG_FUNCTION_ARGS) PG_RETURN_VOID(); } +/* Helper function to modify the label table so that it inherits from other labels. */ +static void change_label_inheritance(char *graph_name, char *label_name, List* parents) +{ + ListCell *lc; + RangeVar* rv; + RangeVar* last_element; + char alter_command[500]; + char inherit_command[500]; + char* parent_table_name; + + if(parents->length != 0 && label_name != NULL) + { + /* Build the SQL command string */ + sprintf(alter_command,"ALTER TABLE \"%s\".\"%s\"", graph_name, label_name); + + last_element = list_nth_cell(parents, parents->length - 1)->data.ptr_value; + + foreach(lc, parents) + { + /* Get the curent cell name by it's OID, add it to inherit_command and concatenate + * it with strcat() with alter_command. */ + rv = lfirst(lc); + parent_table_name = rv->relname; + + /* Check if it is the last element on list and add semicolon. Add a comma if it isn't. */ + if (last_element == rv) + { + sprintf(inherit_command, " INHERIT \"%s\".\"%s\";", graph_name, parent_table_name); + strcat(alter_command, inherit_command); + } + else + { + sprintf(inherit_command, " INHERIT \"%s\".\"%s\",", graph_name, parent_table_name); + strcat(alter_command, inherit_command); + } + + } + + /* Connect to the database using SPI */ + SPI_connect(); + SPI_execute(alter_command, false, 0); + SPI_finish(); + } +} + + /* * For the new label, create an entry in ag_catalog.ag_label, create a * new table and sequence. Returns the oid from the new tuple in * ag_catalog.ag_label. */ Oid create_label(char *graph_name, char *label_name, char label_type, - List *parents, int is_inheriting) + List *parents) { graph_cache_data *cache_data; Oid graph_oid; @@ -401,15 +441,20 @@ Oid create_label(char *graph_name, char *label_name, char label_type, // create a table for the new label create_table_for_label(graph_name, label_name, schema_name, rel_name, - seq_name, label_type, parents, is_inheriting); + seq_name, label_type); // record the new label in ag_label relation_id = get_relname_relid(rel_name, nsp_id); // If a label has parents, switch the parents id default, with its own. if (list_length(parents) != 0) + { change_label_id_default(graph_name, label_name, schema_name, seq_name, relation_id); + + change_label_inheritance(graph_name, label_name, parents); + } + // associate the sequence with the "id" column alter_sequence_owned_by_for_label(seq_range_var, rel_name); @@ -433,8 +478,7 @@ Oid create_label(char *graph_name, char *label_name, char label_type, // ) static void create_table_for_label(char *graph_name, char *label_name, char *schema_name, char *rel_name, - char *seq_name, char label_type, - List *parents, int is_inheriting) + char *seq_name, char label_type) { CreateStmt *create_stmt; PlannedStmt *wrapper; @@ -449,9 +493,7 @@ static void create_table_for_label(char *graph_name, char *label_name, * Use the parents' column definition list instead, via Postgres' * inheritance system. */ - if (list_length(parents) != 0 && is_inheriting == NO_INHERITANCE) - create_stmt->tableElts = NIL; - else if (label_type == LABEL_TYPE_EDGE) + if (label_type == LABEL_TYPE_EDGE) create_stmt->tableElts = create_edge_table_elements( graph_name, label_name, schema_name, rel_name, seq_name); else if (label_type == LABEL_TYPE_VERTEX) @@ -461,7 +503,6 @@ static void create_table_for_label(char *graph_name, char *label_name, ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("undefined label type \'%c\'", label_type))); - create_stmt->inhRelations = parents; create_stmt->partbound = NULL; create_stmt->ofTypename = NULL; create_stmt->constraints = NIL; diff --git a/src/backend/parser/cypher_clause.c b/src/backend/parser/cypher_clause.c index 6be8a4ea8..4c1032770 100644 --- a/src/backend/parser/cypher_clause.c +++ b/src/backend/parser/cypher_clause.c @@ -4778,7 +4778,7 @@ transform_create_cypher_edge(cypher_parsestate *cpstate, List **target_list, parent = list_make1(rv); create_label(cpstate->graph_name, edge->label, LABEL_TYPE_EDGE, - parent, false); + parent); } // lock the relation of the label @@ -5003,7 +5003,7 @@ transform_create_cypher_new_node(cypher_parsestate *cpstate, parent = list_make1(rv); create_label(cpstate->graph_name, node->label, LABEL_TYPE_VERTEX, - parent, false); + parent); } rel->flags = CYPHER_TARGET_NODE_FLAG_INSERT; @@ -5792,7 +5792,7 @@ transform_merge_cypher_edge(cypher_parsestate *cpstate, List **target_list, // create the label create_label(cpstate->graph_name, edge->label, LABEL_TYPE_EDGE, - parent, false); + parent); } // lock the relation of the label @@ -5896,7 +5896,7 @@ transform_merge_cypher_node(cypher_parsestate *cpstate, List **target_list, // create the label create_label(cpstate->graph_name, node->label, LABEL_TYPE_VERTEX, - parent, false); + parent); } rel->flags |= CYPHER_TARGET_NODE_FLAG_INSERT; diff --git a/src/include/commands/label_commands.h b/src/include/commands/label_commands.h index 40f37c23c..711a56453 100644 --- a/src/include/commands/label_commands.h +++ b/src/include/commands/label_commands.h @@ -60,6 +60,6 @@ Datum create_vlabel(PG_FUNCTION_ARGS); Datum create_elabel(PG_FUNCTION_ARGS); Oid create_label(char *graph_name, char *label_name, char label_type, - List *parents, int is_inheriting); + List *parents); #endif