theory / pgtap

PostgreSQL Unit Testing Suite
https://pgtap.org
990 stars 94 forks source link

Feature: index_is_partial(), index_partial_clause_is() #334

Open halostatue opened 8 months ago

halostatue commented 8 months ago

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;
rodo commented 1 month ago

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

theory commented 4 weeks ago

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

theory commented 4 weeks ago

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

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