Bug: `USE GRAPH` on one connection changes the current graph for every connection on the Database

Open
#1,543 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
54/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
bun, cpp, databases, typescript
Domain
database

Research direction

Start by reproducing the behavior with the two-connection TypeScript example in the issue, then trace how USE GRAPH selects the current graph and how connections share that state. The issue identifies no source files or tests, so locating the relevant implementation will require repository exploration. Done means confirming whether graph selection is intended to be database-wide and, if it should be per connection, showing that connection B still queries main after A switches to alpha.

Written by the indexing model from the issue text.

Description

Ladybug version

@ladybugdb/core 0.22.3 (npm), also seen on 0.23.0-dev.20261105

What operating system are you using?

macOS 27 (arm64), and Linux arm64 in the oven/bun:1.4.4 container. The Node binding was run under Bun 1.4.4.

What happened?

USE GRAPH run on connection A also changes the graph that a second connection, B, reads, even though B never ran USE GRAPH. B's fresh (uncached) query reads the subgraph A switched to instead of main.

This makes subgraphs unsafe for any program that holds more than one connection. For example, a writer connection that switches graphs while a reader connection is querying would send the reader's queries to the wrong graph.

#1274 notes the same database-wide behaviour in passing, as part of a prepared-statement caching bug. This report is about the scope itself: is the current graph meant to be database-wide? If so, it would help to document that. If not, we would expect USE GRAPH to be per connection, like USE DATABASE in relational systems, which the CREATE GRAPH docs compare it to.

Are there known steps to reproduce?
import * as lb from '@ladybugdb/core';

const db = new lb.Database('/tmp/use-graph-scope/g.lbug');
const a = new lb.Connection(db);
const b = new lb.Connection(db);
const run = async (c: lb.Connection, q: string) => (await c.query(q)).getAll();

await run(a, 'CREATE NODE TABLE Entity(key STRING PRIMARY KEY)');
await run(a, "CREATE (:Entity {key: 'in-main'})");
await run(a, 'CREATE GRAPH alpha');
await run(a, 'USE GRAPH alpha');
await run(a, 'CREATE NODE TABLE Entity(key STRING PRIMARY KEY)');
await run(a, "CREATE (:Entity {key: 'in-alpha'})");

// b never ran USE GRAPH
console.log(await run(b, 'MATCH (e:Entity) RETURN e.key'));
// expected: [{ 'e.key': 'in-main' }]
// actual:   [{ 'e.key': 'in-alpha' }]
Dominant language
C++
Stars
1.8k
Forks
148
Avg merge
1d 13h
Merged PRs (30d)
176

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from LadybugDB/ladybug

All issues in LadybugDB/ladybug

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.