|
42 | 42 | #include "catalog/ag_graph.h" |
43 | 43 | #include "catalog/ag_label.h" |
44 | 44 | #include "commands/label_commands.h" |
| 45 | +#include "common/hashfn.h" |
45 | 46 | #include "parser/cypher_analyze.h" |
46 | 47 | #include "parser/cypher_clause.h" |
47 | 48 | #include "parser/cypher_expr.h" |
48 | 49 | #include "parser/cypher_item.h" |
49 | 50 | #include "parser/cypher_parse_agg.h" |
50 | 51 | #include "parser/cypher_transform_entity.h" |
| 52 | +#include "storage/lock.h" |
51 | 53 | #include "utils/ag_cache.h" |
52 | 54 | #include "utils/ag_func.h" |
53 | 55 | #include "utils/ag_guc.h" |
@@ -7222,19 +7224,28 @@ transform_merge_cypher_edge(cypher_parsestate *cpstate, List **target_list, |
7222 | 7224 | /* check to see if the label exists, create the label entry if it does not. */ |
7223 | 7225 | if (edge->label && !label_exists(edge->label, cpstate->graph_oid)) |
7224 | 7226 | { |
| 7227 | + LOCKTAG tag; |
| 7228 | + uint32 key; |
7225 | 7229 | List *parent; |
7226 | | - /* |
7227 | | - * setup the default edge table as the parent table, that we |
7228 | | - * will inherit from. |
7229 | | - */ |
7230 | | - rv = get_label_range_var(cpstate->graph_name, cpstate->graph_oid, |
7231 | | - AG_DEFAULT_LABEL_EDGE); |
7232 | 7230 |
|
7233 | | - parent = list_make1(rv); |
| 7231 | + key = hash_bytes((const unsigned char *)edge->label, strlen(edge->label)); |
| 7232 | + SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key, cpstate->graph_oid, 3); |
| 7233 | + (void) LockAcquire(&tag, ExclusiveLock, false, false); |
| 7234 | + if (!label_exists(edge->label, cpstate->graph_oid)) |
| 7235 | + { |
| 7236 | + /* |
| 7237 | + * setup the default edge table as the parent table, that we |
| 7238 | + * will inherit from. |
| 7239 | + */ |
| 7240 | + rv = get_label_range_var(cpstate->graph_name, cpstate->graph_oid, |
| 7241 | + AG_DEFAULT_LABEL_EDGE); |
7234 | 7242 |
|
7235 | | - /* create the label */ |
7236 | | - create_label(cpstate->graph_name, edge->label, LABEL_TYPE_EDGE, |
7237 | | - parent); |
| 7243 | + parent = list_make1(rv); |
| 7244 | + |
| 7245 | + /* create the label */ |
| 7246 | + create_label(cpstate->graph_name, edge->label, LABEL_TYPE_EDGE, |
| 7247 | + parent); |
| 7248 | + } |
7238 | 7249 | } |
7239 | 7250 |
|
7240 | 7251 | /* lock the relation of the label */ |
@@ -7357,20 +7368,28 @@ transform_merge_cypher_node(cypher_parsestate *cpstate, List **target_list, |
7357 | 7368 | /* check to see if the label exists, create the label entry if it does not. */ |
7358 | 7369 | if (node->label && !label_exists(node->label, cpstate->graph_oid)) |
7359 | 7370 | { |
| 7371 | + LOCKTAG tag; |
| 7372 | + uint32 key; |
7360 | 7373 | List *parent; |
7361 | 7374 |
|
7362 | | - /* |
7363 | | - * setup the default vertex table as the parent table, that we |
7364 | | - * will inherit from. |
7365 | | - */ |
7366 | | - rv = get_label_range_var(cpstate->graph_name, cpstate->graph_oid, |
7367 | | - AG_DEFAULT_LABEL_VERTEX); |
| 7375 | + key = hash_bytes((const unsigned char *)node->label, strlen(node->label)); |
| 7376 | + SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key, cpstate->graph_oid, 3); |
| 7377 | + (void) LockAcquire(&tag, ExclusiveLock, false, false); |
| 7378 | + if (!label_exists(node->label, cpstate->graph_oid)) |
| 7379 | + { |
| 7380 | + /* |
| 7381 | + * setup the default vertex table as the parent table, that we |
| 7382 | + * will inherit from. |
| 7383 | + */ |
| 7384 | + rv = get_label_range_var(cpstate->graph_name, cpstate->graph_oid, |
| 7385 | + AG_DEFAULT_LABEL_VERTEX); |
7368 | 7386 |
|
7369 | | - parent = list_make1(rv); |
| 7387 | + parent = list_make1(rv); |
7370 | 7388 |
|
7371 | | - /* create the label */ |
7372 | | - create_label(cpstate->graph_name, node->label, LABEL_TYPE_VERTEX, |
7373 | | - parent); |
| 7389 | + /* create the label */ |
| 7390 | + create_label(cpstate->graph_name, node->label, LABEL_TYPE_VERTEX, |
| 7391 | + parent); |
| 7392 | + } |
7374 | 7393 | } |
7375 | 7394 |
|
7376 | 7395 | rel->flags |= CYPHER_TARGET_NODE_FLAG_INSERT; |
|
0 commit comments