Aggregating tsqueries

From: Alexander Hill <alex(at)hill(dot)net(dot)au>
To: pgsql-performance(at)postgresql(dot)org
Subject: Aggregating tsqueries
Date: 2014-09-17 04:56:31
Message-ID: CA+KBOKxv7HOcc=VXpcLZWX=s8=2dFpgOZcFOQC9iY-L60VhB4w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hello,

I have a table of tree nodes with a tsquery column. To get a subtree's
tsquery, I need to OR all of its nodes' tsqueries together.

I defined a custom aggregate using tsquery_or:

CREATE AGGREGATE tsquery_or_agg (tsquery)
(
sfunc = tsquery_or,
stype = tsquery
);

but I've found that

tsquery_or_agg(query)

is about a hundred times slower than this:

('(' || string_agg(query::text, ')|(') || ')')::tsquery

That works perfectly so I'm happy to continue doing it, but I'm curious to
know why the difference is so great and if anything can be done about it?

Cheers,
Alex

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Simon Riggs 2014-09-17 17:15:32 Re: Postgres Replaying WAL slowly
Previous Message Huang, Suya 2014-09-17 00:21:58 How to interpret view pg_stat_bgwriter