Fix a performance problem#2
Open
nminoru wants to merge 1 commit into
Open
Conversation
ctidscan uses heap_beginscan() with the scankeys specified by the ctid range, and then heap_getnext() returns tuples that pass the scankeys test. Although this method internally reads all the blocks in the target table. This adds the ctid range test into CTidAccessCustomScan(), so that ctidscan can stop scanning the table as soon as it runs out of the ctid range.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I suspect ctidcan doesn't work well as expected.
For example, the following SELECT reads the first half of T1.
But EXPLAIN shows that all the blocks of T1 are scanned.
CREATE TABLE T1 (C1 INT, C2 TEXT);
INSERT INTO T1 (C1, C2) SELECT i, REPEAT('X', 1000) FROM generate_series(1, 8 * 1000) AS i; --- T1 is 1142 blocks
ANALYZE;
LOAD 'ctidscan';
SELECT max(ctid) FROM T1;
EXPLAIN (ANALYZE ON, BUFFERS ON, COSTS OFF, TIMING OFF) SELECT C1 FROM T1 WHERE ctid < '(500,1)' AND C1 % 2 = 0;
Custom Scan (ctidscan) on t1 (actual rows=1750 loops=1)
Filter: ((ctid < '(500,1)'::tid) AND ((c1 % 2) = 0))
Rows Removed by Filter: 1750
ctid quals: (ctid < '(500,1)'::tid)
Buffers: shared hit=1143 <--- we expect about 500 blocks
I try to fix this problem.
ctidscan uses heap_beginscan() with the scankeys specified by the ctid
range, and then heap_getnext() returns tuples that pass the scankeys test.
Although this method internally reads all the blocks in the target table.
This fix adds the ctid range test into CTidAccessCustomScan(),
so that ctidscan can stop as soon as it runs out of the range.
Would you like to merge my pull request?