Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix #15466 Transform LIMIT or OFFSET first based on order specified in prepared statement#15484

Merged
Mytherin merged 1 commit intoduckdb:mainfrom
ashwaniYDV:limit_offset_prepared_stmt
Feb 6, 2025
Merged

Fix #15466 Transform LIMIT or OFFSET first based on order specified in prepared statement#15484
Mytherin merged 1 commit intoduckdb:mainfrom
ashwaniYDV:limit_offset_prepared_stmt

Conversation

@ashwaniYDV
Copy link
Contributor

@ashwaniYDV ashwaniYDV commented Dec 28, 2024

Fixes #15466

I have utilized a boolean parameter offset_first to check whether OFFSET appears first in the query than LIMIT.
Utilized a third parameter isLimitOffsetFirst in Yacc grammar file.

@ashwaniYDV
Copy link
Contributor Author

ashwaniYDV commented Dec 28, 2024

hi @szarnyasg . I am thinking of this fix.
I will store a 3rd parameter (= offset if offset is first or NULL otherwise) in the list to track whether OFFSET is first or LIMIT is fist in the query.
If my 3rd param in list is equal to offset then offset is first in query otherwise limit is first.

But I am getting one issue that:

Assertion failed: (n < list->length), function list_nth_cell, file src_backend_nodes_list.cpp, line 313.
[1]    27093 abort      ./duckdb

I have already made a list of size 3 using list_make3, but I am getting this assertion error as the list size is 2.

@carlopi
Copy link
Contributor

carlopi commented Dec 28, 2024

hi @szarnyasg . I am thinking of this fix. I will store a 3rd parameter (= offset if offset is first or NULL otherwise) in the list to track whether OFFSET is first or LIMIT is fist in the query. If my 3rd param in list is equal to offset then offset is first in query otherwise limit is first.

But I am getting one issue that:

Assertion failed: (n < list->length), function list_nth_cell, file src_backend_nodes_list.cpp, line 313.
[1]    27093 abort      ./duckdb

I have already made a list of size 3 using list_make3, but I am getting this assertion error as the list size is 2.

I would assume the problem is NOT from one of the places you changed list_make2 -> list_make3, but from other places, like https://github.com/duckdb/duckdb/pull/15484/files#diff-42899531f1aa9bacd2fe999bc94bb896abf1f37503d19993b8b6b0d9a9cf82d1R650.

That said, this is just a hunch, I don't have experience with parsers, other might have a better answer to this. I also can't immediately how this solves the issue the problem, but I guess passing this information down further will.

Be aware that waiting days for a PR review might be expected.

@ashwaniYDV
Copy link
Contributor Author

hi @szarnyasg . I am thinking of this fix. I will store a 3rd parameter (= offset if offset is first or NULL otherwise) in the list to track whether OFFSET is first or LIMIT is fist in the query. If my 3rd param in list is equal to offset then offset is first in query otherwise limit is first.
But I am getting one issue that:

Assertion failed: (n < list->length), function list_nth_cell, file src_backend_nodes_list.cpp, line 313.
[1]    27093 abort      ./duckdb

I have already made a list of size 3 using list_make3, but I am getting this assertion error as the list size is 2.

I would assume the problem is NOT from one of the places you changed list_make2 -> list_make3, but from other places, like https://github.com/duckdb/duckdb/pull/15484/files#diff-42899531f1aa9bacd2fe999bc94bb896abf1f37503d19993b8b6b0d9a9cf82d1R650.

That said, this is just a hunch, I don't have experience with parsers, other might have a better answer to this. I also can't immediately how this solves the issue the problem, but I guess passing this information down further will.

Be aware that waiting days for a PR review might be expected.

thanks for the reply @carlopi

opt_select_limit:
	select_limit						{ $$ = $1; }
	| /* EMPTY */						{ $$ = list_make3(NULL,NULL,NULL); }

here select_limit should return list_make3, so I think this should work

@Mytherin
Copy link
Collaborator

Mytherin commented Jan 3, 2025

Thanks for the PR! The changes seems fine to me but it seems to not be working correctly currently. Can you look at the CI failures?

@ashwaniYDV ashwaniYDV force-pushed the limit_offset_prepared_stmt branch from cf6c823 to e60e603 Compare January 18, 2025 17:57
@duckdb-draftbot duckdb-draftbot marked this pull request as draft January 18, 2025 17:58
@ashwaniYDV ashwaniYDV marked this pull request as ready for review January 18, 2025 17:58
@ashwaniYDV ashwaniYDV changed the title [WIP] Fix #15466 Transform LIMIT or OFFSET first based on order specified in prepared statement Fix #15466 Transform LIMIT or OFFSET first based on order specified in prepared statement Jan 18, 2025
@ashwaniYDV
Copy link
Contributor Author

Thanks for the PR! The changes seems fine to me but it seems to not be working correctly currently. Can you look at the CI failures?

Hi @Mytherin I have fixed the PR. Its working now.
image

@ashwaniYDV ashwaniYDV force-pushed the limit_offset_prepared_stmt branch from e60e603 to b87f3ea Compare January 18, 2025 21:03
@duckdb-draftbot duckdb-draftbot marked this pull request as draft January 18, 2025 21:04
@ashwaniYDV ashwaniYDV marked this pull request as ready for review January 18, 2025 21:04
@ashwaniYDV ashwaniYDV force-pushed the limit_offset_prepared_stmt branch from b87f3ea to 23e8455 Compare January 18, 2025 21:07
@duckdb-draftbot duckdb-draftbot marked this pull request as draft January 18, 2025 21:08
@ashwaniYDV ashwaniYDV marked this pull request as ready for review January 18, 2025 21:08
@ashwaniYDV ashwaniYDV force-pushed the limit_offset_prepared_stmt branch from 23e8455 to 8131f82 Compare January 18, 2025 22:43
@duckdb-draftbot duckdb-draftbot marked this pull request as draft January 18, 2025 22:43
@ashwaniYDV ashwaniYDV marked this pull request as ready for review January 19, 2025 04:44
@ashwaniYDV
Copy link
Contributor Author

@Mytherin I have added test cases as well

@ashwaniYDV
Copy link
Contributor Author

ashwaniYDV commented Jan 21, 2025

hey @Mytherin @szarnyasg. Did you get a chance to review this PR

@Mytherin
Copy link
Collaborator

Thanks - the changes look good

@ashwaniYDV
Copy link
Contributor Author

hi @Mytherin This is my first PR to duckdb. Any ETA when this can be merged?
I would love to be part of the contributors list.

@Mytherin
Copy link
Collaborator

We'll merge it in the coming weeks after the release

@Mytherin Mytherin merged commit cc99c2c into duckdb:main Feb 6, 2025
50 checks passed
@Mytherin
Copy link
Collaborator

Mytherin commented Feb 6, 2025

Thanks!

Antonov548 added a commit to Antonov548/duckdb-r that referenced this pull request Feb 26, 2025
Fix duckdb/duckdb#15466 Transform LIMIT or OFFSET first based on order specified in prepared statement (duckdb/duckdb#15484)
discussions duckdb/duckdb#15981: remove confusing comment in "duckdb/tools/shell/shell.cpp" (duckdb/duckdb#15984)
krlmlr pushed a commit to duckdb/duckdb-r that referenced this pull request Mar 5, 2025
Fix duckdb/duckdb#15466 Transform LIMIT or OFFSET first based on order specified in prepared statement (duckdb/duckdb#15484)
discussions duckdb/duckdb#15981: remove confusing comment in "duckdb/tools/shell/shell.cpp" (duckdb/duckdb#15984)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 15, 2025
Fix duckdb/duckdb#15466 Transform LIMIT or OFFSET first based on order specified in prepared statement (duckdb/duckdb#15484)
discussions duckdb/duckdb#15981: remove confusing comment in "duckdb/tools/shell/shell.cpp" (duckdb/duckdb#15984)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 15, 2025
Fix duckdb/duckdb#15466 Transform LIMIT or OFFSET first based on order specified in prepared statement (duckdb/duckdb#15484)
discussions duckdb/duckdb#15981: remove confusing comment in "duckdb/tools/shell/shell.cpp" (duckdb/duckdb#15984)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 17, 2025
Fix duckdb/duckdb#15466 Transform LIMIT or OFFSET first based on order specified in prepared statement (duckdb/duckdb#15484)
discussions duckdb/duckdb#15981: remove confusing comment in "duckdb/tools/shell/shell.cpp" (duckdb/duckdb#15984)
krlmlr added a commit to duckdb/duckdb-r that referenced this pull request May 18, 2025
Fix duckdb/duckdb#15466 Transform LIMIT or OFFSET first based on order specified in prepared statement (duckdb/duckdb#15484)
discussions duckdb/duckdb#15981: remove confusing comment in "duckdb/tools/shell/shell.cpp" (duckdb/duckdb#15984)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameters for OFFSET and LIMIT in a prepared statement get swapped

3 participants