Skip to content

Commit 1a22134

Browse files
committed
update
1 parent 2a107d5 commit 1a22134

11 files changed

Lines changed: 164 additions & 528 deletions

File tree

postgraph--0.1.0.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ CREATE INDEX ag_label_ltree_index
8383
ON ag_label
8484
USING gist (label_path public.gist_ltree_ops);
8585

86+
CREATE TABLE edge_metatable (
87+
id label_id NOT NULL,
88+
level int NOT NULL,
89+
base_rel regclass NOT NULL,
90+
sub_rel regclass NOT NULL--,
91+
--CONSTRAINT fk_label_id FOREIGN KEY(id) REFERENCES ag_label(id)
92+
);
93+
94+
CREATE INDEX edge_metatable_id
95+
ON edge_metatable
96+
USING btree (id);
97+
98+
CREATE INDEX edge_metatable_id_level
99+
ON edge_metatable
100+
USING btree (id, level);
101+
86102
CREATE TABLE session_graph_use (
87103
pid oid not null,
88104
graph_oid oid not null

regress/sql/cypher_create.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ MATCH () RETURN 1;
4646

4747
CREATE ()-[]->();
4848

49+
SELECT * FROM cypher_create._ag_label_vertex;
50+
51+
SELECT * FROM cypher_create._adj__adj__ag_label_vertex;
52+
SELECT * FROM cypher_create._adj__ag_label_vertex;
4953
MATCH () RETURN 1;
5054

5155
CYPHER WITH 1 as a

regress/sql/vertex_am.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
LOAD 'postgraph';
2020
set search_path 'postgraph';
21-
21+
/*
2222
CREATE TABLE vertex_am_tst (id postgraph.graphid not null, props postgraph.gtype not null) USING vertex_adjlist;
2323
2424
@@ -29,7 +29,7 @@ VALUES ('1'::postgraph.graphid, postgraph.gtype_build_map('id', 1));
2929
SELECT '1'::postgraph.graphid OPERATOR(postgraph.=) '1'::postgraph.graphid;
3030
EXPLAIN SELECT * FROM vertex_am_tst WHERE id OPERATOR(postgraph.=) '1'::postgraph.graphid;
3131
SELECT * FROM vertex_am_tst WHERE id OPERATOR(postgraph.=) '1'::postgraph.graphid;
32-
/*
32+
3333
DELETE FROM vertex_am_tst;
3434
3535

src/backend/access/vertex_heap/vertex_heapam_handler.c

Lines changed: 68 additions & 511 deletions
Large diffs are not rendered by default.

src/backend/commands/label_commands.c

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static void range_var_callback_for_remove_relation(const RangeVar *rel,
9494
Oid odl_rel_oid,
9595
void *arg);
9696
static char *make_vertex_adjlist_alias(char *var_name);
97-
97+
static List *create_edge_table_elements_topmost(void);
9898

9999
PG_FUNCTION_INFO_V1(create_vlabel);
100100
Datum create_vlabel(PG_FUNCTION_ARGS)
@@ -523,7 +523,7 @@ void create_vertex_adjlist(char *graph_name, char *label_name) {
523523
create_stmt->relation = makeRangeVar(graph_name, rel_name, -1);
524524

525525

526-
create_stmt->tableElts = create_vertex_adjlist_table_elements();
526+
create_stmt->tableElts = create_edge_table_elements_topmost();
527527

528528

529529
create_stmt->inhRelations = NIL;
@@ -625,6 +625,12 @@ void create_label(char *graph_name, char *label_name, char label_type,
625625
if (label_type == 'v') {
626626
create_vertex_adjlist(graph_name, label_name);
627627
Oid adj_oid = get_relname_relid(make_vertex_adjlist_alias(label_name), nsp_id);
628+
629+
// 08/2/25: TODO - this is incorrect, but it will allow me to get the first two edge table I need created.
630+
// So do it for now, change in the very near future
631+
create_label(graph_name, make_vertex_adjlist_alias(make_vertex_adjlist_alias(label_name)), 'e', NIL , NULL);
632+
633+
628634
insert_label(label_name, graph_oid, label_id, label_type, relation_id, NULL, adj_oid);
629635

630636
}else {
@@ -693,6 +699,43 @@ static void create_table_for_label(char *graph_name, char *label_name,
693699
// CommandCounterIncrement() is called in ProcessUtility()
694700
}
695701

702+
703+
// CREATE TABLE `schema_name`.`rel_name` (
704+
// "id" graphid PRIMARY KEY DEFAULT CATALOG_SCHEMA."_graphid"(...),
705+
// "start_id" graphid NOT NULL
706+
// "end_id" graphid NOT NULL
707+
// "properties" gtype NOT NULL DEFAULT CATALOG_SCHEMA."gtype_build_map"()
708+
// )
709+
static List *create_edge_table_elements_topmost(void)
710+
{
711+
ColumnDef *id;
712+
ColumnDef *start_id;
713+
ColumnDef *end_id;
714+
ColumnDef *props;
715+
716+
// "id" graphid PRIMARY KEY DEFAULT CATALOG_SCHEMA."_graphid"(...)
717+
id = makeColumnDef(AG_EDGE_COLNAME_ID, GRAPHIDOID, -1, InvalidOid);
718+
id->constraints = NIL;
719+
720+
// "start_id" graphid NOT NULL
721+
start_id = makeColumnDef(AG_EDGE_COLNAME_START_ID, GRAPHIDOID, -1,
722+
InvalidOid);
723+
start_id->constraints = list_make1(build_not_null_constraint());
724+
725+
// "end_id" graphid NOT NULL
726+
end_id = makeColumnDef(AG_EDGE_COLNAME_END_ID, GRAPHIDOID, -1, InvalidOid);
727+
end_id->constraints = list_make1(build_not_null_constraint());
728+
729+
// "properties" gtype NOT NULL DEFAULT CATALOG_SCHEMA."gtype_build_map"()
730+
props = makeColumnDef(AG_EDGE_COLNAME_PROPERTIES, GTYPEOID, -1,
731+
InvalidOid);
732+
props->constraints = list_make2(build_null_constraint(),
733+
build_properties_default());
734+
735+
return list_make4(id, start_id, end_id, props);
736+
}
737+
738+
696739
// CREATE TABLE `schema_name`.`rel_name` (
697740
// "id" graphid PRIMARY KEY DEFAULT CATALOG_SCHEMA."_graphid"(...),
698741
// "start_id" graphid NOT NULL

src/backend/executor/cypher_create.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ static void begin_cypher_create(CustomScanState *node, EState *estate, int eflag
194194
// Open all indexes for the relation
195195
ExecOpenIndices(cypher_node->resultRelInfo, false);
196196

197-
198197
// Setup the relation's tuple slot
199198
cypher_node->elemTupleSlot = table_slot_create(rel, &estate->es_tupleTable);
200199

@@ -290,9 +289,6 @@ static TupleTableSlot *exec_cypher_create(CustomScanState *csnode)
290289

291290
}
292291

293-
294-
//TODO: the edges aren't setup to use this. I gotta get the correct relid in cypher_target_node.
295-
// Then I gotta get any existing tuple, and update it if it exists, and insert if it doesn't
296292
for (int i = 0; i < list_length(path->target_nodes)/2 + 1; i++) {
297293
cypher_target_node *node = (cypher_target_node *)list_nth(path->target_nodes, i * 2);
298294

@@ -330,9 +326,15 @@ static TupleTableSlot *exec_cypher_create(CustomScanState *csnode)
330326
elemTupleSlot->tts_values[0] = css->edge_ids[0][i];
331327
elemTupleSlot->tts_isnull[0] = false;
332328

329+
elemTupleSlot->tts_values[1] = css->vertex_ids[0][i];
330+
elemTupleSlot->tts_isnull[1] = false;
331+
332+
elemTupleSlot->tts_values[2] = css->vertex_ids[0][i+1];
333+
elemTupleSlot->tts_isnull[2] = false;
333334
// get the properties for this vertex
334-
elemTupleSlot->tts_values[1] = NULL;
335-
elemTupleSlot->tts_isnull[1] = true;
335+
elemTupleSlot->tts_values[3] = NULL;
336+
elemTupleSlot->tts_isnull[3] = true;
337+
336338
// Insert the new vertex
337339
insert_entity_tuple(resultRelInfo, elemTupleSlot, estate);
338340
}
@@ -364,8 +366,12 @@ static void end_cypher_create(CustomScanState *node)
364366
continue;
365367

366368
ExecCloseIndices(cypher_node->resultRelInfo);
369+
table_close(cypher_node->resultRelInfo->ri_RelationDesc, RowExclusiveLock);
367370
ExecCloseIndices(cypher_node->adj_resultRelInfo);
368371
table_close(cypher_node->adj_resultRelInfo->ri_RelationDesc, RowExclusiveLock);
372+
373+
374+
369375
}
370376
}
371377
}
@@ -454,8 +460,6 @@ static void insert_vertex(cypher_create_custom_scan_state *css,
454460
/*
455461
* Insert the edge/vertex tuple into the table and indices. Check that the
456462
* table's constraints have not been violated.
457-
*
458-
* This function uses the passed cid for updates.
459463
*/
460464
HeapTuple insert_entity_tuple(ResultRelInfo *resultRelInfo,
461465
TupleTableSlot *elemTupleSlot,
@@ -464,14 +468,14 @@ HeapTuple insert_entity_tuple(ResultRelInfo *resultRelInfo,
464468
HeapTuple tuple = NULL;
465469

466470
ExecStoreVirtualTuple(elemTupleSlot);
467-
tuple = ExecFetchSlotHeapTuple(elemTupleSlot, true, NULL);
471+
// tuple = ExecFetchSlotHeapTuple(elemTupleSlot, true, NULL);
468472

469473
/* Check the constraints of the tuple */
470-
tuple->t_tableOid = RelationGetRelid(resultRelInfo->ri_RelationDesc);
471-
if (resultRelInfo->ri_RelationDesc->rd_att->constr != NULL)
474+
//tuple->t_tableOid = resultRelInfo->ri_RelationDesc->rd_id;
475+
/* if (resultRelInfo->ri_RelationDesc->rd_att->constr != NULL)
472476
{
473477
ExecConstraints(resultRelInfo, elemTupleSlot, estate);
474-
}
478+
}*/
475479

476480
// Insert the tuple normally
477481
table_tuple_insert(resultRelInfo->ri_RelationDesc, elemTupleSlot, estate->es_output_cid, 0, NULL);
@@ -482,7 +486,7 @@ HeapTuple insert_entity_tuple(ResultRelInfo *resultRelInfo,
482486
ExecInsertIndexTuples(resultRelInfo, elemTupleSlot, estate, false, false, NULL, NIL);
483487
}
484488

485-
return tuple;
489+
return NULL;
486490
}
487491

488492

src/backend/postgraph.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "optimizer/cypher_paths.h"
2828
#include "parser/cypher_analyze.h"
2929
#include "access/vertex.h"
30+
#include "executor/nodeSeqscan.h"
3031

3132
PG_MODULE_MAGIC;
3233

src/backend/utils/cache/ag_cache.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ typedef struct label_relation_cache_entry
8888
label_cache_data data;
8989
} label_relation_cache_entry;
9090

91+
9192
// ag_graph.name
9293
static HTAB *graph_name_cache_hash = NULL;
9394
static ScanKeyData graph_name_scan_keys[1];

src/include/access/vertex.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ typedef struct VertexScanDescData
2121

2222
TableScanDescData rs_base; /* AM independent part of the descriptor */
2323

24+
int ndesc;
25+
TableScanDesc **desc;
26+
27+
2428
/* Hash value of the scan key, ie, the hash key we seek */
2529
uint32 hashso_sk_hash;
2630

src/include/catalog/ag_label.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
#define ag_label_label_index_id() \
6464
ag_relation_id("ag_label_ltree_index", "index")
6565

66+
#define edge_metatable_id() \
67+
ag_relation_id("edge_metatable_id", "index")
68+
#define edge_metatable_id_level() \
69+
ag_relation_id("edge_metatable_id_level", "index")
70+
6671
#define LABEL_ID_SEQ_NAME "_label_id_seq"
6772

6873
#define LABEL_KIND_VERTEX 'v'

0 commit comments

Comments
 (0)