xpath index not being used

From: Irooniam <irooniam(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: xpath index not being used
Date: 2010-07-18 21:41:41
Message-ID: AANLkTik2TtydDYr1rjdpIrcHPi2Dy6rfIBC8-p8-S8e5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I've searched the mailing list and I tried using defining a xpath index per
the post, but my query is still not using it.

Essentially, I'm storing a fragment of xml and I want to create xpath
indexes on them.

The two rows I'm going to insert look like this (alex & bob are the only
names repeated):
<names><name>frank</name><name>mason</name><name>bob</name><name>alex</name></names>
<names><name>alex</name><name>bob</name><name>cola</name><name>doda</name></names>

create table test (data xml);
CREATE TABLE

CREATE INDEX name_test ON test (((xpath('//names/name/text()',
data))[1]::text));
CREATE INDEX

I can select with a where clause without issue:
select * from test where ((xpath('//names/name[. ="bob"]/text()',
data))[1]::text) = 'bob';

data
--------------------------------------------------------------------------------------
<names><name>alex</name><name>bob</name><name>cola</name><name>doda</name></names>
<names><name>frank</name><name>mason</name><name>bob</name><name>alex</name></names>
(2 rows)

However, when I check which index it's using, it's not using the xpath
index:
explain select * from test where ((xpath('//names/name[. ="bob"]/text()',
data))[1]::text) = 'bob';
QUERY
PLAN
---------------------------------------------------------------------------------------------------------
Seq Scan on test (cost=0.00..1.03 rows=1 width=32)
Filter: (((xpath('//names/name[. ="bob"]/text()'::text, data,
'{}'::text[]))[1])::text = 'bob'::text)
(2 rows)

Any help on what I'm doing wrong would be appreciated.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andre Lopes 2010-07-18 21:51:48 How to change the file encoding of a 3gb file?
Previous Message Scott Marlowe 2010-07-18 21:41:21 Re: Differences between Postgres and MySql