pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Masahiro Ikeda <ikedamsh@oss.nttdata.com>
To: pgsql-hackers@postgresql.org
Subject: Fix to increment the index scan counter for the bloom filter index
Date: Tue, 12 Nov 2024 19:01:47 +0900
Message-ID: <c48839d881388ee401a01807c686004d@oss.nttdata.com> (raw)

Hi,

I noticed that the bloom filter index forgets to increment the index 
scan counter
while reviewing the skip scan patch [1]. It seems this was simply 
overlooked in
the implementation. What do you think?


# A test case:
## HEAD: 3f323eba89fb

CREATE EXTENSION bloom ;
CREATE TABLE tbloom AS
    SELECT
      (random() * 1000000)::int as i1,
      (random() * 1000000)::int as i2,
      (random() * 1000000)::int as i3,
      (random() * 1000000)::int as i4,
      (random() * 1000000)::int as i5,
      (random() * 1000000)::int as i6
    FROM
   generate_series(1,10000000);
CREATE INDEX bloomidx ON tbloom USING bloom (i1, i2, i3, i4, i5, i6);
ANALYZE;

psql=# SELECT * FROM pg_stat_user_indexes ;
-[ RECORD 1 ]-+---------
relid         | 16384
indexrelid    | 16398
schemaname    | public
relname       | tbloom
indexrelname  | bloomidx
idx_scan      | 0
last_idx_scan |
idx_tup_read  | 0
idx_tup_fetch | 0

psql=# SET enable_seqscan = off;
psql=# EXPLAIN ANALYZE SELECT * FROM tbloom WHERE i2 = 898732 AND i5 = 
123451;

postgres=# SELECT * FROM pg_stat_user_indexes ;
-[ RECORD 1 ]-+---------
relid         | 16384
indexrelid    | 16398
schemaname    | public
relname       | tbloom
indexrelname  | bloomidx
idx_scan      | 0                       # was not incremented
last_idx_scan |                         #
idx_tup_read  | 2362                    # was incremented. It indicates 
that an index scan was executed
idx_tup_fetch | 0


## HEAD with the v1 patch

-- after EXPLAIN ANALYZE ...
postgres=# SELECT * FROM pg_stat_user_indexes ;
-[ RECORD 1 ]-+------------------------------
relid         | 16395
indexrelid    | 16398
schemaname    | public
relname       | tbloom
indexrelname  | bloomidx
idx_scan      | 1                                   # was incremented 
too
last_idx_scan | 2024-11-12 18:15:39.270747+09       #
idx_tup_read  | 2503                                #
idx_tup_fetch | 0


[1] 
https://www.postgresql.org/message-id/flat/CAH2-Wz%3DM_8UCPpD5GQuJXmQZ6xePwhVSss38TmkBAwic12VvCg%40m...

Regards,
-- 
Masahiro Ikeda
NTT DATA CORPORATION

Attachments:

  [text/x-diff] v1-0001-Modify-to-increment-the-index-scan-counter-for-Bl.patch (918B, ../c48839d881388ee401a01807c686004d@oss.nttdata.com/2-v1-0001-Modify-to-increment-the-index-scan-counter-for-Bl.patch)
  download | inline diff:
From 33fed0e2d5754a8adba44122c73779be4d7385bb Mon Sep 17 00:00:00 2001
From: Masahiro Ikeda <ikedamsh@oss.nttdata.com>
Date: Tue, 12 Nov 2024 18:22:11 +0900
Subject: [PATCH v1] Modify to increment the index scan counter for the
bloom filter index.

---
 contrib/bloom/blscan.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/contrib/bloom/blscan.c b/contrib/bloom/blscan.c
index bf455e579f..0c5fb725e8 100644
--- a/contrib/bloom/blscan.c
+++ b/contrib/bloom/blscan.c
@@ -15,6 +15,7 @@
 #include "access/relscan.h"
 #include "bloom.h"
 #include "miscadmin.h"
+#include "pgstat.h"
 #include "storage/bufmgr.h"
 
 /*
@@ -114,6 +115,7 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
 	 */
 	bas = GetAccessStrategy(BAS_BULKREAD);
 	npages = RelationGetNumberOfBlocks(scan->indexRelation);
+	pgstat_count_index_scan(scan->indexRelation);
 
 	for (blkno = BLOOM_HEAD_BLKNO; blkno < npages; blkno++)
 	{
-- 
2.34.1



view thread (4+ messages)  latest in thread

Message-ID: <c48839d881388ee401a01807c686004d@oss.nttdata.com>
Permalink:  ../c48839d881388ee401a01807c686004d@oss.nttdata.com/
Also on:    postgresql.org/message-id/c48839d881388ee401a01807c686004d@oss.nttdata.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: ikedamsh@oss.nttdata.com
  Subject: Re: Fix to increment the index scan counter for the bloom filter index
  In-Reply-To: <c48839d881388ee401a01807c686004d@oss.nttdata.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox