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

[planbuilder] Limit allows unsigned ints #2350

Merged
merged 1 commit into from
Feb 28, 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
5 changes: 5 additions & 0 deletions enginetest/queries/procedure_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ END;`,
"create table t (i int primary key);",
"insert into t values (0), (1), (2), (3)",
"CREATE PROCEDURE limited(the_limit int, the_offset bigint) SELECT * FROM t LIMIT the_limit OFFSET the_offset",
"CREATE PROCEDURE limited_uns(the_limit int unsigned, the_offset bigint unsigned) SELECT * FROM t LIMIT the_limit OFFSET the_offset",
},
Assertions: []ScriptTestAssertion{
{
Expand All @@ -1173,6 +1174,10 @@ END;`,
Query: "call limited(2,2)",
Expected: []sql.Row{{2}, {3}},
},
{
Query: "call limited_uns(2,2)",
Expected: []sql.Row{{2}, {3}},
},
{
Query: "CREATE PROCEDURE limited_inv(the_limit CHAR(3), the_offset INT) SELECT * FROM t LIMIT the_limit OFFSET the_offset",
ExpectedErrStr: "the variable 'the_limit' has a non-integer based type: char(3) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin",
Expand Down
2 changes: 1 addition & 1 deletion sql/planbuilder/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (b *Builder) buildLimitVal(inScope *scope, e ast.Expr) sql.Expression {
if col, ok := inScope.proc.GetVar(e.String()); ok {
// proc param is OK
if pp, ok := col.scalarGf().(*expression.ProcedureParam); ok {
if !pp.Type().Promote().Equals(types.Int64) {
if !pp.Type().Promote().Equals(types.Int64) && !pp.Type().Promote().Equals(types.Uint64) {
err := fmt.Errorf("the variable '%s' has a non-integer based type: %s", pp.Name(), pp.Type().String())
b.handleErr(err)
}
Expand Down
Loading