You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECT * FROM orders WHERE user_id IN (SELECT id FROM users WHERE status = 'VIP')
Say that the subquery here returns the IDs 1 and 2. We fetched those rows in text format, then
We decoded those rows into the Datum type; Datum::Bigint(1), Datum::Bigint(2)
We encoded the Datums again (Array::encode) into the array {1,2}
We sent the array to the shards as $1 of the rewritten statement SELECT * FROM orders WHERE user_id IN (SELECT u.c1 FROM unnest($1::pg_catalog._int8) u(c1))
Steps 1 and 2 here used to act as intermediate steps for a decode -> re-encode process that are now replaced with a binary -> binary conversion (data row binary -> bind parameter binary), as we don't need the decoded values elsewhere.
How? This forces all subqueries we execute to use the binary format (even if client requested text) to allow binary -> binary for massive speedup. This is fine, as the client never sees the rows of those subqueries; we only use them to rewrite the outer statement.
This gives us two advantages, (1) a performance increase, (2) being able to handle values that our decoding / encoding process doesn't support or has bugs for.
Measured to be roughly a 30% performance improvement of subquery handling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Previously, for a statement such as
Say that the subquery here returns the IDs 1 and 2. We fetched those rows in text format, then
Datumtype;Datum::Bigint(1),Datum::Bigint(2)Array::encode) into the array{1,2}SELECT * FROM orders WHERE user_id IN (SELECT u.c1 FROM unnest($1::pg_catalog._int8) u(c1))Steps 1 and 2 here used to act as intermediate steps for a decode -> re-encode process that are now replaced with a binary -> binary conversion (data row binary -> bind parameter binary), as we don't need the decoded values elsewhere.
How? This forces all subqueries we execute to use the binary format (even if client requested text) to allow binary -> binary for massive speedup. This is fine, as the client never sees the rows of those subqueries; we only use them to rewrite the outer statement.
This gives us two advantages, (1) a performance increase, (2) being able to handle values that our decoding / encoding process doesn't support or has bugs for.
Measured to be roughly a 30% performance improvement of subquery handling.