Detailed index predicate with \d on indexes in psql

Started by Greg Sabino Mullaneover 24 years ago2 messageshackers
Jump to latest
#1Greg Sabino Mullane
greg@turnstep.com

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(This is using 7.2b1)

Anyone know why I am getting the "internal form" of the
partial-index predicate? In other words, instead of
getting something like this (thanks Tom):

regression=# \d apple
Index "apple"
Column | Type
- ---------+---------
topping | integer
hash
Index predicate: (topping > 99)

I get something like this:

Index "apple"
Column | Type
- ---------+---------
topping | integer
hash for table "pizza" WHERE (topping > 2000)
Index predicate: ({ EXPR :typeOid 16 :opType op :oper { OPER :opno 521 :opid 14
7 :opresulttype 16 } :args ({ VAR :varno 1 :varattno 3 :vartype 23 :vartypmod -1
:varlevelsup 0 :varnoold 1 :varoattno 3} { CONST :consttype 23 :constlen 4 :co
nstbyval true :constisnull false :constvalue 4 [ 99 0 0 0 ] })})

Doing a:

SELECT c.relname, i.indpred
FROM pg_index i, pg_class c
WHERE c.oid = i.indexrelid
and i.indpred like '(%'

reveals that this is happening to every partial index I
create.

I'm also wondering if we even need the "Index predicate:"
section at all? When it works properly, will it ever give
more information than what the tail end of pg_get_indexdef
returns? If it gives the same, is one preferred over the other?

Thanks,
Greg Sabino Mullane
greg@turnstep.com
PGP Key: 0x14964AC8 200111131146

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iQA/AwUBO/FOorybkGcUlkrIEQL9KACgyJu7YFWCjJQPwEL32yjhmegocRYAn1iC
4djb4ZoOkrSDePXJ6rsQcSCW
=M66f
-----END PGP SIGNATURE-----

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Greg Sabino Mullane (#1)
Re: Detailed index predicate with \d on indexes in psql

"Greg Sabino Mullane" <greg@turnstep.com> writes:

Anyone know why I am getting the "internal form" of the
partial-index predicate?

If you look in describe.c, you'll see that what psql is printing is
the result of
SELECT pg_get_expr(i.indpred, i.indrelid) as indpred
FROM pg_index i
which should yield the exact same text as what pg_get_indexdef offers
in WHERE. Have you mucked with this SELECT? Are you perhaps trying
to run against a pre-7.2 server (pg_get_expr is new in 7.2)?

I'm also wondering if we even need the "Index predicate:"
section at all?

Not if you intend to print the results of pg_get_indexdef instead.

regards, tom lane