From bb75ce2cf2e201c8a001a4db31e8ce7cfe970084 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 12 Mar 2023 12:24:20 -0700 Subject: [PATCH] Fixed index scan count --- CHANGELOG.md | 4 ++++ src/ivfscan.c | 4 ++++ test/t/007_inserts.pl | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5338387..05a62d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.1 (unreleased) + +- Fixed index scan count + ## 0.4.0 (2023-01-11) If upgrading with Postgres < 13, see [this note](https://github.com/pgvector/pgvector#040). diff --git a/src/ivfscan.c b/src/ivfscan.c index 2fcaf3b..85e7f08 100644 --- a/src/ivfscan.c +++ b/src/ivfscan.c @@ -5,6 +5,7 @@ #include "access/relscan.h" #include "ivfflat.h" #include "miscadmin.h" +#include "pgstat.h" #include "storage/bufmgr.h" #include "catalog/pg_operator_d.h" @@ -267,6 +268,9 @@ ivfflatgettuple(IndexScanDesc scan, ScanDirection dir) { Datum value; + /* Count index scan for stats */ + pgstat_count_index_scan(scan->indexRelation); + /* Safety check */ if (scan->orderByData == NULL) elog(ERROR, "cannot scan ivfflat index without order"); diff --git a/test/t/007_inserts.pl b/test/t/007_inserts.pl index 85f354c..cc9e8e9 100644 --- a/test/t/007_inserts.pl +++ b/test/t/007_inserts.pl @@ -2,7 +2,7 @@ use strict; use warnings; use PostgresNode; use TestLib; -use Test::More tests => 5; +use Test::More tests => 7; my $dim = 768; @@ -32,10 +32,16 @@ $node->pgbench( } ); +sub idx_scan +{ + $node->safe_psql("postgres", "SELECT idx_scan FROM pg_stat_user_indexes WHERE indexrelid = 'tst_v_idx'::regclass;"); +} + my $expected = 10000 + 5 * 100 * 10; my $count = $node->safe_psql("postgres", "SELECT COUNT(*) FROM tst;"); is($count, $expected); +is(idx_scan(), 0); $count = $node->safe_psql("postgres", qq( SET enable_seqscan = off; @@ -43,3 +49,4 @@ $count = $node->safe_psql("postgres", qq( SELECT COUNT(*) FROM (SELECT v FROM tst ORDER BY v <-> (SELECT v FROM tst LIMIT 1)) t; )); is($count, $expected); +is(idx_scan(), 1);