Skip to content

EXISTS causes panic #2321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gregoryjjb opened this issue Jun 11, 2023 · 0 comments · Fixed by #2334
Closed

EXISTS causes panic #2321

gregoryjjb opened this issue Jun 11, 2023 · 0 comments · Fixed by #2334

Comments

@gregoryjjb
Copy link

gregoryjjb commented Jun 11, 2023

Version

main (734e06ede7e68dc76e53f41727285abe5301dc69)

What happened?

Using a WHERE EXISTS () subquery in sqlite is causing a panic. This is caused (I believe) by #2274, which added this slice access operation which is out of bounds for some reason.

As far as I can tell the playground only has the latest release, not the main branch, so I can't reproduce it on there.

Relevant log output

panic: runtime error: slice bounds out of range [1:0]

goroutine 6 [running]:
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convertInSelectNode(0xc0012d9cc0?, 0xc000c63e60)
        C:/Development/contributing/sqlc/internal/engine/sqlite/convert.go:637 +0x9e7
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convert(0xc00129a2d0?, {0x7ff652abe8a0?, 0xc000c63e60?})
        C:/Development/contributing/sqlc/internal/engine/sqlite/convert.go:926 +0x2e5
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convertMultiSelect_stmtContext(0x7ff651047fa9?, 0xc001288a50)
        C:/Development/contributing/sqlc/internal/engine/sqlite/convert.go:324 +0x13f1
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convert(0xc0012d9cc0?, {0x7ff652abe9a0?, 0xc001288a50?})
        C:/Development/contributing/sqlc/internal/engine/sqlite/convert.go:942 +0x485
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convertSql_stmtContext(0x0?, 0xc001288a38)
        C:/Development/contributing/sqlc/internal/engine/sqlite/convert.go:529 +0xe3d
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*cc).convert(0xc000807970?, {0x7ff652abe9c0?, 0xc001288a38?})
        C:/Development/contributing/sqlc/internal/engine/sqlite/convert.go:945 +0x4fc
github.com/kyleconroy/sqlc/internal/engine/sqlite.(*Parser).Parse(0xc00003a340?, {0x7ff652ac2560?, 0xc0010877c0?})
        C:/Development/contributing/sqlc/internal/engine/sqlite/parse.go:77 +0x77d
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).parseQueries(0xc00022d800, {{0x10?, 0x9c?, {0x0?, 0x1?}, 0x1?}})
        C:/Development/contributing/sqlc/internal/compiler/compile.go:102 +0x3ad
github.com/kyleconroy/sqlc/internal/compiler.(*Compiler).ParseQueries(...)
        C:/Development/contributing/sqlc/internal/compiler/engine.go:49
github.com/kyleconroy/sqlc/internal/cmd.parse({_, _}, {_, _}, {_, _}, {{0xc00033c426, 0x6}, {0xc0002e9c10, 0x1, ...}, ...}, ...)
        C:/Development/contributing/sqlc/internal/cmd/generate.go:350 +0x285
github.com/kyleconroy/sqlc/internal/cmd.Generate.func1()
        C:/Development/contributing/sqlc/internal/cmd/generate.go:224 +0x5c7
golang.org/x/sync/errgroup.(*Group).Go.func1()
        C:/Users/Greg/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:75 +0x64
created by golang.org/x/sync/errgroup.(*Group).Go
        C:/Users/Greg/go/pkg/mod/golang.org/x/[email protected]/errgroup/errgroup.go:72 +0xa5

Database schema

CREATE TABLE movies (
  id             INTEGER PRIMARY KEY,
  title          TEXT NOT NULL,
  year           TEXT NOT NULL,
  imdb_id        TEXT NOT NULL UNIQUE,
  tmdb_id        TEXT NOT NULL UNIQUE,
  tagline        TEXT NOT NULL,
  overview       TEXT NOT NULL,
  content_rating TEXT NOT NULL,
  runtime        INTEGER NOT NULL,
  poster_image   TEXT,
  backdrop_image TEXT
);

SQL queries

SELECT * FROM movies WHERE EXISTS (SELECT TRUE);

Configuration

sql:
  - schema: "migrations-2"
    queries: "sql"
    engine: "sqlite"
    gen:
      go:
        package: "queries"
        out: "internal/db/queries"
        output_db_file_name: "queries.go"
        emit_json_tags: true

Playground URL

As far as I can tell the playground only has the latest release, not the main branch, so I can't reproduce it on there.

What operating system are you using?

Linux, Windows

What database engines are you using?

SQLite

What type of code are you generating?

Go

@gregoryjjb gregoryjjb added bug Something isn't working triage New issues that hasn't been reviewed labels Jun 11, 2023
@kyleconroy kyleconroy changed the title EXISTS causes panic EXISTS causes panic Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants