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

Allow non-btree operator pushdown in UPDATE/DELETE queries on compressed chunks #7649

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

svenklemm
Copy link
Member

When pushing down expressions into the compressed scan we assumed
all valid expressions use btree operators and dropped any that weren't.
This patch changes the behaviour to keep those expressions and use
them as heap filter on the compressed scan for UPDATE and DELETE
on compressed chunks.

Copy link

github-actions bot commented Feb 3, 2025

@mkindahl, @antekresic: please review this pull request.

Powered by pull-review

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 81.30%. Comparing base (59f50f2) to head (8f153bd).
Report is 730 commits behind head on main.

Files with missing lines Patch % Lines
tsl/src/compression/compression_scankey.c 50.00% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7649      +/-   ##
==========================================
+ Coverage   80.06%   81.30%   +1.23%     
==========================================
  Files         190      241      +51     
  Lines       37181    44754    +7573     
  Branches     9450    11173    +1723     
==========================================
+ Hits        29770    36385    +6615     
- Misses       2997     3977     +980     
+ Partials     4414     4392      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@svenklemm svenklemm requested a review from akuzm February 3, 2025 15:41
@svenklemm svenklemm force-pushed the non-btree-operator branch 2 times, most recently from 1beea0c to 8974147 Compare February 3, 2025 15:54
@svenklemm svenklemm added this to the v2.18.1 milestone Feb 3, 2025
Comment on lines 488 to +491
create_segment_filter_scankey(Relation in_rel, char *segment_filter_col_name,
StrategyNumber strategy, Oid subtype, ScanKeyData *scankeys,
int *num_scankeys, Bitmapset **null_columns, Datum value,
bool is_null_check, bool is_array_op)
StrategyNumber strategy, Oid subtype, Oid opcode,
ScanKeyData *scankeys, int *num_scankeys, Bitmapset **null_columns,
Datum value, bool is_null_check, bool is_array_op)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function has a little too many parameters, maybe we should make it take the BatchFilter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had the same thought but not all callers have a batchfilter

Copy link
Contributor

@antekresic antekresic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I suggest adding a TODO to pull out the opcode logic from create_segment_filter_scankey function so its a bit more cleaner and takes less arguments.

Copy link
Contributor

@mkindahl mkindahl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one case that seems like it could be a potential problem, so might be good to make sure that this is not the case.

Comment on lines 559 to 561
Assert(OidIsValid(opr));
/* We should never end up here but: no opcode, no optimization */
if (!OidIsValid(opr))
return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... several of the callers assume that setting up the scan key succeeds, which means that in a production build, if this for any reason does not have an opcode, the scan key will not be set up, but execution will continue in the caller under the assumption that the scankey is set up.

I see that we do not increase the num_scankeys here, so this might be safe, but give that there is an assert here it seems like we should deal with this as an error.

For example, if the scankey is not added in this function and it is not added as a filter (because the assumption was that this function succeeded), then we will actually end up in a similar position as before and delete more data than what should be deleted.

One other option is to raise an error here instead, e.g., using Ensure?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure would be a breaking change and certainly not appropriate for a patch release. This function has multiple return false when certain conditions are not met and num_scankeys is only increased when we actually add a scankey. None of the callers assume this always succeeds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what happens with the scan key in that case? Is it kept as a filter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scankey is only allocated at the end of the function when everything succeeds. I've removed the assert since it didnt serve a purpose.

@svenklemm svenklemm force-pushed the non-btree-operator branch 4 times, most recently from 2035a88 to 24c9f1b Compare February 4, 2025 13:31
…sed chunks

When pushing down expressions into the compressed scan we assumed
all valid expressions use btree operators and dropped any that weren't.
This patch changes the behaviour to keep those expressions and use
them as heap filter on the compressed scan for UPDATE and DELETE
on compressed chunks.
@svenklemm svenklemm merged commit 1c1743d into timescale:main Feb 4, 2025
44 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants