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

match range key with range type #2294

Merged
merged 4 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions enginetest/queries/query_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -5241,6 +5241,42 @@ CREATE TABLE tab3 (
},
},
},
{
Name: "range query convert int to string zero value",
SetUpScript: []string{
`CREATE TABLE t0(c0 VARCHAR(500));`,
`INSERT INTO t0(c0) VALUES ('a');`,
`INSERT INTO t0(c0) VALUES ('1');`,
`CREATE TABLE t1(c0 INTEGER, PRIMARY KEY(c0));`,
`INSERT INTO t1(c0) VALUES (0);`,
`INSERT INTO t1(c0) VALUES (1);`,
`INSERT INTO t1(c0) VALUES (2);`,
},
Assertions: []ScriptTestAssertion{
{
Query: "SELECT /*+ LOOKUP_JOIN(t0,t1) JOIN_ORDER(t0,t1) */ * FROM t1 INNER JOIN t0 ON ((t0.c0)=(t1.c0));",
Expected: []sql.Row{
{0, "a"},
{1, "1"},
},
},
{
Query: "INSERT INTO t0(c0) VALUES ('2abc');",
Expected: []sql.Row{
{types.OkResult{RowsAffected: 1}},
},
},
{
Skip: true,
Query: "SELECT /*+ LOOKUP_JOIN(t0,t1) JOIN_ORDER(t0,t1) */ * FROM t1 INNER JOIN t0 ON ((t0.c0)=(t1.c0));",
Expected: []sql.Row{
{0, "a"},
{1, "1"},
{2, "2abc"},
},
},
},
},
}

var SpatialScriptTests = []ScriptTest{
Expand Down
21 changes: 16 additions & 5 deletions sql/plan/indexed_table_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,14 +559,25 @@ func (lb *LookupBuilder) GetLookup(key lookupBuilderKey) (sql.IndexLookup, error
if lb.matchesNullMask[i] {
if key[i] == nil {
lb.rang[i] = sql.NullRangeColumnExpr(lb.cets[i].Type)

} else {
lb.rang[i].LowerBound = sql.Below{Key: key[i]}
lb.rang[i].UpperBound = sql.Above{Key: key[i]}
k, _, err := lb.rang[i].Typ.Convert(key[i])
if err != nil {
// TODO: throw warning, and this should truncate for strings
err = nil
k = lb.rang[i].Typ.Zero()
}
lb.rang[i].LowerBound = sql.Below{Key: k}
lb.rang[i].UpperBound = sql.Above{Key: k}
}
} else {
lb.rang[i].LowerBound = sql.Below{Key: key[i]}
lb.rang[i].UpperBound = sql.Above{Key: key[i]}
k, _, err := lb.rang[i].Typ.Convert(key[i])
if err != nil {
// TODO: throw warning, and this should truncate for strings
err = nil
k = lb.rang[i].Typ.Zero()
}
lb.rang[i].LowerBound = sql.Below{Key: k}
lb.rang[i].UpperBound = sql.Above{Key: k}
}
}

Expand Down
Loading