Skip to content
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

Panic when Using BETWEEN and CASE WHEN #7154

Closed
suyZhong opened this issue Dec 13, 2023 · 0 comments · Fixed by dolthub/go-mysql-server#2203
Closed

Panic when Using BETWEEN and CASE WHEN #7154

suyZhong opened this issue Dec 13, 2023 · 0 comments · Fixed by dolthub/go-mysql-server#2203
Labels

Comments

@suyZhong
Copy link

The following test case caused runtime error: invalid memory address or nil pointer dereference.

CREATE TABLE t0(c0 INTEGER);

SELECT t0.c0 FROM t0 WHERE (t0.c0 BETWEEN (CASE 1 WHEN 2 THEN 1.0 ELSE (1||2) END ) AND t0.c0);

Here's my error trace:

ERRO[1391] mysql_server caught panic:
runtime error: invalid memory address or nil pointer dereference
/home/suyang/go/src/runtime/panic.go:261 (0x454617)
        panicmem: panic(memoryError)
/home/suyang/go/src/runtime/signal_unix.go:861 (0x4545e5)
        sigpanic: panicmem()
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/session.go:376 (0xa3e2c7)
        com/dolthub/go-mysql-server/sql.(*Context).Span: if c.tracer == NoopTracer {
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/expression/case.go:160 (0x1715c76)
        com/dolthub/go-mysql-server/sql/expression.(*Case).Eval: span, ctx := ctx.Span("expression.Case")
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/costed_index_scan.go:1274 (0x1ba16a8)
        com/dolthub/go-mysql-server/sql/analyzer.newLeaf: value, err := right.Eval(nil, nil)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/costed_index_scan.go:510 (0x1b9e0f4)
        com/dolthub/go-mysql-server/sql/analyzer.(*indexCoster).flattenAnd: leaf, ok := newLeaf(c.i, e, c.underlyingName)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/costed_index_scan.go:442 (0x1b9d927)
        com/dolthub/go-mysql-server/sql/analyzer.(*indexCoster).flatten: invalid, imprecise := c.flattenAnd(e, newAnd)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/costed_index_scan.go:101 (0x1b9b3a4)
        com/dolthub/go-mysql-server/sql/analyzer.costedIndexScans.func1: root, leftover, imprecise := c.flatten(filter.Expression)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/transform/node.go:353 (0x1740171)
        com/dolthub/go-mysql-server/sql/transform.Node: node, sameN, err := f(node)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/transform/node.go:330 (0x174007b)
        com/dolthub/go-mysql-server/sql/transform.Node: child, same, err := Node(child, f)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/costed_index_scan.go:54 (0x1b9ab6c)
        com/dolthub/go-mysql-server/sql/analyzer.costedIndexScans: return transform.Node(n, func(n sql.Node) (sql.Node, transform.TreeIdentity, error) {
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/batch.go:89 (0x1b96c4a)
        com/dolthub/go-mysql-server/sql/analyzer.(*Batch).evalOnce: next, same, err = rule.Apply(ctx, a, prev, scope, sel)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/batch.go:63 (0x1b9694e)
        com/dolthub/go-mysql-server/sql/analyzer.(*Batch).EvalWithSelector: cur, _, err := b.evalOnce(ctx, a, n, scope, sel)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/batch.go:55 (0x1b8d384)
        com/dolthub/go-mysql-server/sql/analyzer.(*Batch).Eval: return b.EvalWithSelector(ctx, a, n, scope, sel)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/analyzer.go:530 (0x1b8cfe7)
        com/dolthub/go-mysql-server/sql/analyzer.(*Analyzer).analyzeWithSelector: n, same, err = batch.Eval(ctx, a, n, scope, ruleSelector)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/sql/analyzer/analyzer.go:490 (0x1c16415)
        com/dolthub/go-mysql-server/sql/analyzer.(*Analyzer).Analyze: n, _, err := a.analyzeWithSelector(ctx, n, scope, SelectAllBatches, DefaultRuleSelector)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/engine.go:600 (0x1c163f8)
        com/dolthub/go-mysql-server.(*Engine).analyzeQuery: analyzed, err = e.Analyzer.Analyze(ctx, parsed, nil)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/engine.go:496 (0x1c157c6)
        com/dolthub/go-mysql-server.(*Engine).QueryWithBindings: analyzed, err = e.analyzeQuery(ctx, query, bound)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/server/handler.go:265 (0x1ecf2d6)
        com/dolthub/go-mysql-server/server.(*Handler).doQuery: schema, rowIter, err := h.e.QueryWithBindings(ctx, query, parsed, bindings)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/server/handler.go:463 (0x1ed10de)
        com/dolthub/go-mysql-server/server.(*Handler).errorWrappedDoQuery: remainder, err := h.doQuery(c, query, parsed, mode, bindings, callback)
/home/suyang/go/pkg/mod/github.com/dolthub/go-mysql-server@v0.17.1-0.20231212224504-9831b84717bd/server/handler.go:177 (0x1ece9a8)
        com/dolthub/go-mysql-server/server.(*Handler).ComMultiQuery: return h.errorWrappedDoQuery(c, query, nil, MultiStmtModeOn, nil, callback)
/home/suyang/go/pkg/mod/github.com/dolthub/vitess@v0.0.0-20231207010700-88fb35413580/go/mysql/conn.go:1456 (0x9cff89)
        com/dolthub/vitess/go/mysql.(*Conn).execQuery: remainder, err = handler.ComMultiQuery(c, query, resultsCB)
/home/suyang/go/pkg/mod/github.com/dolthub/vitess@v0.0.0-20231207010700-88fb35413580/go/mysql/conn.go:972 (0x9cb639)
        com/dolthub/vitess/go/mysql.(*Conn).handleNextCommand: for query, err = c.execQuery(query, handler, multiStatements); err == nil && query != ""; {
/home/suyang/go/pkg/mod/github.com/dolthub/vitess@v0.0.0-20231207010700-88fb35413580/go/mysql/server.go:499 (0x9e7e58)
        com/dolthub/vitess/go/mysql.(*Listener).handle: err := c.handleNextCommand(l.handler)
/home/suyang/go/src/runtime/asm_amd64.s:1650 (0x4738c0)
        goexit: BYTE    $0x90   // NOP 

I originally find this by building dolt from source version d7678ab. Could also reproduce on 1.29.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants