Skip to content

Fix a performance problem#2

Open
nminoru wants to merge 1 commit into
kaigai:masterfrom
nminoru:performance_improvement
Open

Fix a performance problem#2
nminoru wants to merge 1 commit into
kaigai:masterfrom
nminoru:performance_improvement

Conversation

@nminoru
Copy link
Copy Markdown
Contributor

@nminoru nminoru commented Oct 19, 2016

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;

                   QUERY PLAN

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?

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.
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.

1 participant