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

fix(engine/dolphin): Fixed problem that LIMIT OFFSET cannot be used with UNION ALL #2613

Merged
merged 2 commits into from
Aug 28, 2023
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
35 changes: 35 additions & 0 deletions internal/endtoend/testdata/select_union/mysql/go/query.sql.go

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

6 changes: 6 additions & 0 deletions internal/endtoend/testdata/select_union/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ SELECT * FROM foo
UNION
SELECT * FROM foo;

-- name: SelectUnionWithLimit :many
SELECT * FROM foo
UNION
SELECT * FROM foo
LIMIT ? OFFSET ?;

-- name: SelectExcept :many
SELECT * FROM foo
EXCEPT
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ SELECT * FROM foo
UNION
SELECT * FROM foo;

-- name: SelectUnionWithLimit :many
SELECT * FROM foo
UNION
SELECT * FROM foo
LIMIT $1 OFFSET $2;

-- name: SelectExcept :many
SELECT * FROM foo
EXCEPT
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ SELECT * FROM foo
UNION
SELECT * FROM foo;

-- name: SelectUnionWithLimit :many
SELECT * FROM foo
UNION
SELECT * FROM foo
LIMIT $1 OFFSET $2;

-- name: SelectExcept :many
SELECT * FROM foo
EXCEPT
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ SELECT * FROM foo
UNION
SELECT * FROM foo;

-- name: SelectUnionWithLimit :many
SELECT * FROM foo
UNION
SELECT * FROM foo
LIMIT $1 OFFSET $2;

-- name: SelectExcept :many
SELECT * FROM foo
EXCEPT
Expand Down
7 changes: 6 additions & 1 deletion internal/engine/dolphin/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,12 @@ func (c *cc) convertSetOprSelectList(n *pcast.SetOprSelectList) ast.Node {

func (c *cc) convertSetOprStmt(n *pcast.SetOprStmt) ast.Node {
if n.SelectList != nil {
return c.convertSetOprSelectList(n.SelectList)
sn := c.convertSetOprSelectList(n.SelectList)
if ss, ok := sn.(*ast.SelectStmt); ok && n.Limit != nil {
ss.LimitOffset = c.convert(n.Limit.Offset)
ss.LimitCount = c.convert(n.Limit.Count)
}
return sn
}
return todo(n)
}
Expand Down
Loading