Avoid scanning non-default partitions #662
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a minimal change to address #660.
It changes one query from selecting the max timestamp in a given partition (which may incur a full table scan) to selecting any timestamp (which should be fast).
Testing. I tested it with:
Proof. I'll argue that the query change does not change the behavior of the function.
Let P be the partition being iterated on.
If it's empty, then
v_max_timestamp
evaluates to null in both old and new code, and the loop iteration does nothing in both old and new code.Let's then consider a non empty partition P.
Let A (for any timestamp) be the timestamp returned by the new code, and let M (for max) be that returned by the old code.
We have A <= M.
If A >= CURRENT_TIMESTAMP then
show_partition_name
gives back P for both old and new code. (Using A or M doesn't make a difference, as they're both in P.)Let's look at the case when A < CURRENT_TIMESTAMP.
If also M < CURRENT_TIMESTAMP, both the old and the new code would use CURRENT_TIMESTAMP, so no difference.
It remans to consider the case
in which case CURRENT_TIMESTAMP still belongs to partition P, so the old code (uses M) and the new code (uses CURRENT_TIMESTAMP) both return P.