Re: Very slow query (3-4mn) on a table with 25millions rows

From: Félix GERZAGUET <felix(dot)gerzaguet(at)gmail(dot)com>
To: Abadie Lana <Lana(dot)Abadie(at)iter(dot)org>
Cc: Martín Marqués <martin(at)2ndquadrant(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Very slow query (3-4mn) on a table with 25millions rows
Date: 2016-07-27 09:36:44
Message-ID: CANVwZtsM4u2ZJH4ChzpR5byi74zxG7RL+XD5w292XHZaS6UDng@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Wed, Jul 27, 2016 at 11:15 AM, Félix GERZAGUET <felix(dot)gerzaguet(at)gmail(dot)com
> wrote:

> I don't know how to give the planner more accurate info ...
>

Could you try to materialize the e.name subquery in another table. As in

create table func_var_name_for_tpl_15 as
select e.name
from
functionalvariables e
,
usertemplatevariable ut
where
e.usertemplatevar_id=ut.id
and
ut.usertempl_id=15
;

Then analyse that table
Then try the rewritten query:

with filtered_s as (
select s.attvalue
from functionalvarattributes s
, tags t
, variableattributetypes vat
where t.id=s.tag_id
and t.status!='Internal'
and vat.fieldtype in ('DBF_INLINK','DBF_OUTLINK','DBF_FWDLINK')
and vat.id=s.atttype_id
and split_part(split_part(s.attvalue,' ',1),'.',1) in ( select e.name
from
func_var_name_for_tpl_15
e
)
)
select s.attvalue
from filtered_s s
except
select s.attvalue
from filtered_s s
, usertemplvarattribute utva
, usertemplatevariable utv
where utv.id=utva.usertempvariable_fk
and utv.usertempl_id=15
;

Does it use the vat_funcvaratt_multi_idx index now ?

--
Félix

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Abadie Lana 2016-07-27 14:55:16 Re: Very slow query (3-4mn) on a table with 25millions rows
Previous Message Félix GERZAGUET 2016-07-27 09:15:49 Re: Very slow query (3-4mn) on a table with 25millions rows