postrgesql query planner wrong desicion

From: Kenny Bachman <kenny(dot)bachman17(at)gmail(dot)com>
To: pgsql-admin(at)lists(dot)postgresql(dot)org
Subject: postrgesql query planner wrong desicion
Date: 2022-06-17 08:48:00
Message-ID: CAC0w7LKM16y0FuBBqMP6wkaRR2JHvLjYcSg-O8URerH4_8Yi2g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hello Team,

I have a 12.11 postgresql database on Linux. When I ran the below query,
the query planner uses the gist index. However, the query runs faster if I
drop the gist index, because the query planner uses the b-tree index. Why
does the query planner use the gist index instead of the b-tree?

SELECT DISTINCT w."InstanceId",
w."LastStepId" ,
sl."SlaPercent",
sl."RemainingSla" ,
sl."DefaultSla" ,
sl."PriorityScore",
sl."KpiDuration" ,
sl."E2EDurationHour" ,
sl."E2EDurationDay" ,
sl."E2EDurationHour" ,
sl."E2EDurationDay" ,
sl."TeamDuration" AS "GroupTime",
poolsource."PartyId",
sl."SLASTATUS"
FROM dsi."Pool_Datasource" poolsource
JOIN dsi."Instance" w ON poolsource."InstanceId" = w."InstanceId"
AND NOT (EXISTS ( SELECT 1 FROM dsi."Pool_Party" WHERE *"Pool_Party"."Code"
= 'TEAM-FIXPOWERUSER'*
AND poolsource."RelatedPartyId" = "Pool_Party"."PartyId"))
AND w."ApplicationCd" = 'SolIncident'
LEFT JOIN dsi."Records" sl ON sl."InstanceId" = w."InstanceId"
LEFT JOIN dsi."Tickets" tc ON tc."WFINSTANCEID" = w."InstanceId"
WHERE w."LastStepId" = poolsource."StepId" AND w."EntityStatusCd" <>
'CLOSE' AND
NOT (EXISTS (SELECT 1 FROM dsi."Tickets" tc_1
WHERE tc_1."OLDPLATFORMCODE" = 'Davinci' AND tc_1."TICKETTYPEID" = 1
AND w."InstanceId" = tc_1."WFINSTANCEID"
AND (tc_1."STATUS" = ANY (ARRAY['SOLUTION', 'REJECT']))));

With GIST Index: (Total exec time : 34s)

Index Scan using "Pool_Party_Code_gist" on "Pool_Party" (cost=0.28..8.30
rows=1 width=4) (actual time=0.097..0.097 rows=1 loops=330870)
Index Cond: (("Code")::text =
'TEAM-FIXPOWERUSER'::text)

Without GIST Index: (Total exec time: 4s)

Index Scan using "Pool_Party_Code_idx" on "Pool_Party" (cost=0.42..8.44
rows=1 width=4) (actual time=0.007..0.007 rows=1 loops=330870)
Index Cond: (("Code")::text =
'TEAM-FIXPOWERUSER'::text)

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Bo Victor Thomsen 2022-06-17 09:34:23 Re: Postgres performance issue
Previous Message Julien Rouhaud 2022-06-17 02:00:06 Re: Postgres performance issue