Skip to content

Implement CREATE GRAPH#123

Merged
adsharma merged 18 commits intomasterfrom
create_graph
Jan 5, 2026
Merged

Implement CREATE GRAPH#123
adsharma merged 18 commits intomasterfrom
create_graph

Conversation

@adsharma
Copy link
Copy Markdown
Contributor

@adsharma adsharma commented Jan 3, 2026

CREATE GRAPH mygraph;
USE mygraph;
CREATE NODE TABLE ...
CREATE REL TABLE ...

This concept is similar to how postgres handles multiple databases in one instance.

Implement graph namespaces that provide catalog-level isolation, allowing
tables with the same name to exist in different graphs.

Changes:
- Grammar: Add CREATE GRAPH and USE GRAPH statements to Cypher.g4
- Parser: Add GraphStatement, CreateGraph, UseGraph AST nodes
- Binder: Add BoundCreateGraph, BoundUseGraph bound statements
- Planner: Add LogicalCreateGraph, LogicalUseGraph operators
- Processor: Add CreateGraph, UseGraph physical operators
- DatabaseManager: Store separate catalogs per graph
- Catalog: Return graph catalog when default graph is set

Tests: Add e2e tests for multi-graph table isolation

Note: Storage is shared at database level. For complete data isolation,
graph-specific storage paths would be needed.
Modify show_tables() to:
- Show tables from all graphs and the main database
- Display graph names as "<name>(graph)" in the database column
- Add getGraphs() method to DatabaseManager for iterating all graphs
- update tests to clean up test tables in all graphs
Implement DROP GRAPH to complement CREATE GRAPH and USE GRAPH for
complete graph catalog isolation. Users can now:
- Create isolated graphs with CREATE GRAPH <name>
- Switch between graphs with USE GRAPH <name>
- Drop graphs with DROP GRAPH <name>

Key changes:
- Add GRAPH to DropType enum
- Implement dropGraph() in DatabaseManager and Drop operator
- Fix error types to use BinderException for graph-related errors
- Update tests to verify all graph operations including error cases

Note: Cannot drop a graph that is currently in use - must switch away first.
- Remove SKIP_FSM_LEAK_CHECK from all test cases
- Add proper cleanup to each test using DROP GRAPH
- Modify dropGraph to clear defaultGraph to "local" when dropping current graph
- Simplified DropGraph test by removing unnecessary SwitchAwayAndDrop section

This makes the behavior more user-friendly - you can now drop a graph even
if it's currently in use, and it will automatically switch to "local".
- Add special case in setDefaultGraph to accept "local" (case-insensitive)
- Add test for USE GRAPH local

Users can now switch back to the main database with: USE GRAPH local;
- USE GRAPH main switches to main database
- LOCAL_DB_NAME changed from local(lbug) to main(graph)
- SHADOW_DB_NAME changed from shadow(lbug) to shadow(graph)
- Test updated to reflect new naming

The (graph) suffix is more intuitive since lbug is the database type.
- Catalog now owns its own StorageManager via unique_ptr
- DatabaseManager::createGraph() creates a separate StorageManager for each graph
- StorageManager::Get() looks up the storage manager from the graph catalog
- Fix circular include: remove catalog.h from storage_manager.h header,
  move to storage_manager.cpp, use forward declarations in header
Use the main storage manager during drop graph <name>, so we don't crash
by accessing memory that's already been freed.
@adsharma adsharma merged commit c7b2279 into master Jan 5, 2026
25 checks passed
@adsharma adsharma deleted the create_graph branch January 5, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant