Re: Custom explain options

From: Konstantin Knizhnik <knizhnik(at)garret(dot)ru>
To: vignesh C <vignesh21(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Custom explain options
Date: 2024-01-10 13:56:53
Message-ID: 3c2eac5c-96ac-4b2c-8fbc-4c791ccf892c@garret.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 09/01/2024 10:33 am, vignesh C wrote:
> On Sat, 21 Oct 2023 at 18:34, Konstantin Knizhnik <knizhnik(at)garret(dot)ru> wrote:
>> Hi hackers,
>>
>> EXPLAIN statement has a list of options (i.e. ANALYZE, BUFFERS, COST,...) which help to provide useful details of query execution.
>> In Neon we have added PREFETCH option which shows information about page prefetching during query execution (prefetching is more critical for Neon
>> architecture because of separation of compute and storage, so it is implemented not only for bitmap heap scan as in Vanilla Postgres, but also for seqscan, indexscan and indexonly scan). Another possible candidate for explain options is local file cache (extra caching layer above shared buffers which is used to somehow replace file system cache in standalone Postgres).
>>
>> I think that it will be nice to have a generic mechanism which allows extensions to add its own options to EXPLAIN.
>> I have attached the patch with implementation of such mechanism (also available as PR: https://github.com/knizhnik/postgres/pull/1 )
>>
>> I have demonstrated this mechanism using Bloom extension - just to report number of Bloom matches.
>> Not sure that it is really useful information but it is used mostly as example:
>>
>> explain (analyze,bloom) select * from t where pk=2000;
>> QUERY PLAN
>> -------------------------------------------------------------------------------------------------------------------------
>> Bitmap Heap Scan on t (cost=15348.00..15352.01 rows=1 width=4) (actual time=25.244..25.939 rows=1 loops=1)
>> Recheck Cond: (pk = 2000)
>> Rows Removed by Index Recheck: 292
>> Heap Blocks: exact=283
>> Bloom: matches=293
>> -> Bitmap Index Scan on t_pk_idx (cost=0.00..15348.00 rows=1 width=0) (actual time=25.147..25.147 rows=293 loops=1)
>> Index Cond: (pk = 2000)
>> Bloom: matches=293
>> Planning:
>> Bloom: matches=0
>> Planning Time: 0.387 ms
>> Execution Time: 26.053 ms
>> (12 rows)
>>
>> There are two known issues with this proposal:
> There are few compilation errors reported by CFBot at [1] with:
> [05:00:40.452] ../src/backend/access/brin/brin.c: In function
> ‘_brin_end_parallel’:
> [05:00:40.452] ../src/backend/access/brin/brin.c:2675:3: error: too
> few arguments to function ‘InstrAccumParallelQuery’
> [05:00:40.452] 2675 |
> InstrAccumParallelQuery(&brinleader->bufferusage[i],
> &brinleader->walusage[i]);
> [05:00:40.452] | ^~~~~~~~~~~~~~~~~~~~~~~
> [05:00:40.452] In file included from ../src/include/nodes/execnodes.h:33,
> [05:00:40.452] from ../src/include/access/brin.h:13,
> [05:00:40.452] from ../src/backend/access/brin/brin.c:18:
> [05:00:40.452] ../src/include/executor/instrument.h:151:13: note: declared here
> [05:00:40.452] 151 | extern void InstrAccumParallelQuery(BufferUsage
> *bufusage, WalUsage *walusage, char* custusage);
> [05:00:40.452] | ^~~~~~~~~~~~~~~~~~~~~~~
> [05:00:40.452] ../src/backend/access/brin/brin.c: In function
> ‘_brin_parallel_build_main’:
> [05:00:40.452] ../src/backend/access/brin/brin.c:2873:2: error: too
> few arguments to function ‘InstrEndParallelQuery’
> [05:00:40.452] 2873 |
> InstrEndParallelQuery(&bufferusage[ParallelWorkerNumber],
> [05:00:40.452] | ^~~~~~~~~~~~~~~~~~~~~
> [05:00:40.452] In file included from ../src/include/nodes/execnodes.h:33,
> [05:00:40.452] from ../src/include/access/brin.h:13,
> [05:00:40.452] from ../src/backend/access/brin/brin.c:18:
> [05:00:40.452] ../src/include/executor/instrument.h:150:13: note: declared here
> [05:00:40.452] 150 | extern void InstrEndParallelQuery(BufferUsage
> *bufusage, WalUsage *walusage, char* custusage);
>
> [1] - https://cirrus-ci.com/task/5452124486631424?logs=build#L374
>
> Regards,
> Vignesh

Thank you for reporting the problem.
Rebased version of the patch is attached.

Attachment Content-Type Size
custom_explain_options-v2.patch text/plain 34.7 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2024-01-10 13:59:42 Re: System username in pg_stat_activity
Previous Message Bertrand Drouvot 2024-01-10 13:56:13 Re: System username in pg_stat_activity