pgtap icon indicating copy to clipboard operation
pgtap copied to clipboard

Feature: index_is_partial(), index_partial_clause_is()

Open halostatue opened this issue 1 year ago • 3 comments
trafficstars

It would be useful to be able see if an index is partial and what the clause is.

For index_is_partial, we can get that with:

SELECT x.indpred IS NOT NULL
  FROM pg_catalog.pg_index x
  JOIN pg_catalog.pg_class ct    ON ct.oid = x.indrelid
  JOIN pg_catalog.pg_class ci    ON ci.oid = x.indexrelid
  JOIN pg_catalog.pg_namespace n ON n.oid = ct.relnamespace
 WHERE ct.relname = $table
   AND ci.relname = $index
   AND n.nspname  = $schema;

For index_partial_clause_is, we can get the string for the partial clause as:

SELECT pg_get_expr(x.indpred, x.indrelid)
  FROM pg_catalog.pg_index x
  JOIN pg_catalog.pg_class ct    ON ct.oid = x.indrelid
  JOIN pg_catalog.pg_class ci    ON ci.oid = x.indexrelid
  JOIN pg_catalog.pg_namespace n ON n.oid = ct.relnamespace
 WHERE ct.relname = $table
   AND ci.relname = $index
   AND n.nspname  = $schema;

halostatue avatar Mar 22 '24 18:03 halostatue

Hi @halostatue I started to work on your request, please see the attached pull request. If everything go fine, it should be in the 1.3.4 version

rodo avatar Oct 25 '24 13:10 rodo

Heya @rodo, is that in #334? Is it ready to review?

theory avatar Nov 05 '24 12:11 theory

Heya @rodo, is that in #334? Is it ready to review?

Bah, no, it's #342, sorry.

theory avatar Nov 05 '24 13:11 theory