Re: Streaming read-ready sequential scan code
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Melanie Plageman <melanieplageman@gmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>,
Andres Freund <andres@anarazel.de>, David Rowley <dgrowleyml@gmail.com>, Heikki Linnakangas <hlinnaka@iki.fi>, Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2024-08-27T06:52:44Z
Lists: pgsql-hackers
Attachments
- 0001-Fix-unfairness-in-all-cached-parallel-seq-scan.patch (text/x-patch) patch 0001
Here's a really simple way to see the new unfairness at the end of a
parallel scan:
drop table if exists t;
create table t (i int);
insert into t select generate_series(1, 100000);
alter table t set (parallel_workers = 2);
set parallel_setup_cost = 0;
set parallel_leader_participation = off;
explain (analyze, buffers, verbose) select count(*) from t;
On my machine, unpatched master shows:
Worker 0: actual time=0.036..12.452 rows=51076 loops=1
Buffers: shared hit=226
Worker 1: actual time=0.037..12.003 rows=48924 loops=1
Buffers: shared hit=217
The attached patch, which I'd like to push, is effectively what
Alexander tested (blocknums[16] -> blocknums[1]). There's no point in
using an array of size 1, so I've turned it into a simple variable and
deleted the relevant comments. My machine shows:
Worker 0: actual time=0.038..12.115 rows=49946 loops=1
Buffers: shared hit=221
Worker 1: actual time=0.038..12.109 rows=50054 loops=1
Buffers: shared hit=222
That difference may not seem huge, but other pre-existing things are
going pathologically wrong in the reported query that magnify it (see
my earlier analysis). It's an interesting problem that will require
more study (my earlier analysis missed a detail that I'll write about
separately), but it doesn't seem to be new or have easy fixes, so that
will have to be for later work.
Commits
-
Fix unfairness in all-cached parallel seq scan.
- 3ed3683618cb 17.0 landed
- 4effd0844daf 18.0 landed
-
Fix if/while thinko in read_stream.c edge case.
- 158f58192368 17.0 landed
-
Increase default vacuum_buffer_usage_limit to 2MB.
- 98f320eb2ef0 17.0 landed
-
Allow BufferAccessStrategy to limit pin count.
- 3bd8439ed628 17.0 landed
-
Improve read_stream.c's fast path.
- aa1e8c206454 17.0 landed
-
Secondary refactor of heap scanning functions
- 3a4a3537a999 17.0 landed
-
Preliminary refactor of heap scanning functions
- 44086b097537 17.0 landed
-
Add VACUUM/ANALYZE BUFFER_USAGE_LIMIT option
- 1cbbee033857 16.0 cited