Skip to content

Lint: JOIN u ON 1=1 and ON t.id = t.id get no finding, so a full cartesian product passes the gate and runs #156

Closed

Description

@laaielichter

GV003 catches a join without a condition, and GV008 catches a join condition without an equality. A condition that contains an = but does not relate the two tables slips between the two rules: Gulliver sees an equality, concludes it is a key join, and reports nothing.

gulliver lint "select a from t join u on 1=1 limit 5"
# No scale problems found.

gulliver lint "select t.a from t join u on t.id = t.id limit 5"
# No scale problems found.

# for comparison, the same cartesian product written three other ways
gulliver lint "select a from t join u on true limit 5"
# warn  GV008 non-equi-join: Join with u uses a non-equality or OR condition; ...
gulliver lint "select a from t, u where t.x > 3 limit 5"
# error GV003 cartesian-join: Join with u has no join condition: a cartesian product.
gulliver lint "select a from t cross join u limit 5"
# warn  GV003 cartesian-join: CROSS JOIN with u multiplies row counts (rows A x rows B).

Because nothing is reported, the gate stays open:

gulliver demo --events 20000
gulliver --dsn gulliver_demo.duckdb run "select count(*) from events e join users u on 1=1"
# **run** on `default` (duckdb) - **OK**        <- 20,000 x 100,000 = 2 billion row pairs, no lint finding

ON 1=1 is a habit of query builders and of agents that "need a join condition"; ON t.id = t.id is the typo version (the same alias on both sides). Both are exactly what the tool is meant to stop.

Checked on current main (2bdae73). Why: in the GV003 / GV008 block of src/gulliver/lint.py the test is has_eq = any(True for _ in on.find_all(exp.EQ)); any EQ node counts, whatever its two sides are.

What should happen

An ON condition only counts as a key join when at least one equality compares a column of the joined table with a column of another table. Otherwise:

  • no column at all in the condition (ON 1=1, ON TRUE, ON 'a' = 'a'): GV003 error, the same finding as a join without a condition (today ON TRUE is a GV008 warning; it is the same cartesian product)
  • every equality has the same table on both sides (ON t.id = t.id, ON u.x = u.y): GV003 error as well, with a message that says the condition does not link the two tables
  • a real key plus a constant (ON t.id = u.id AND 1=1, ON t.id = u.id AND u.kind = 'x'): no finding, as today
  • columns without a table qualifier (ON id = user_id): no finding; Gulliver cannot know which side they come from, so it must not guess
  • USING (...), NATURAL JOIN, UNNEST / LATERAL joins and CROSS JOIN behave as today

Where to start

  • src/gulliver/lint.py: the GV003 / GV008 block inside lint(...) (around lines 247-287). _join_condition(...) (line 93) and _aliases_in(...) (line 97) are the helpers; for each exp.EQ in the ON, collect the table of the exp.Column nodes on the left and on the right and compare them with the joined table's alias (alias in that loop)
  • A join like a JOIN b ON ... JOIN c ON a.id = b.id (the third table is never linked) is the same problem one level up; it is fine to leave it out, say so in the PR
  • Tests: tests/test_lint.py, next to test_non_equi_join (line 89). The repo's own SQL in tests/ and the README examples must stay free of new findings
  • README.md "Scale lint rules" is generated from gulliver rules --format markdown; update the GV003 description in lint.py if the wording changes and regenerate the table

How to test

gulliver lint "select a from t join u on 1=1 limit 5"                      # now: error GV003
gulliver lint "select t.a from t join u on t.id = t.id limit 5"            # now: error GV003
gulliver lint "select t.a from t join u on t.id = u.id and 1=1 limit 5"    # still: No scale problems found.
pytest tests/test_lint.py

Done when

  • ON 1=1, ON TRUE and ON t.id = t.id are reported as GV003 errors and block preflight / run
  • A key equality between the two tables, with or without extra constant conditions, gives no finding
  • Unqualified columns and USING give no new finding
  • Tests for each case above
  • A line under Unreleased in CHANGELOG.md
  • pytest and ruff check . pass

Please comment with your plan before writing a lot of code, as CONTRIBUTING.md asks for bigger changes.

Comment here to claim it and you'll be assigned.

Activity

  1. Ipsita-Mondal-30 commented on Nov 14, 2026

    @Ipsita-Mondal-30
    Contributor

    Hi, I'd like to work on this. I'll open a PR with tests shortly.

  2. laaielichter commented on Nov 14, 2026

    @laaielichter
    OwnerAuthor

    Welcome to Gulliver, @Ipsita-Mondal-30, and thanks for picking this up! I've assigned you #156 (and #157, where you also commented). I see you already opened PRs #164 and #165, so I'll review them. If you haven't yet, CONTRIBUTING.md lists the checks to run before review (pytest, ruff check .) and the CHANGELOG line under Unreleased.

    If Gulliver is useful to you, a ⭐ helps other people find it.


    Generated by Claude Code

  3. added a commit that references this issue on Nov 15, 2026
  4. added a commit that references this issue on Nov 15, 2026
    a055603
  5. added 2 commits that reference this issue on Nov 16, 2026
    f8c6bca
    14602f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions