Slow index scan - Pgsql 9.2

From: Patrick B <patrickbakerbr(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Slow index scan - Pgsql 9.2
Date: 2017-01-10 01:06:34
Message-ID: CAJNY3iu69154gMdFzKNonTU0HTYLk39X_H=u9TFW5JFR6L9wdw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi guys,

I've got the following Query:

WITH

query_p AS (

SELECT CAST(6667176 AS
BIGINT) AS client_id),

clients AS (

SELECT

client.id
,client.job_share_mode

FROM

customers AS
client

WHERE

(client.clientid
= (SELECT qp.client_id FROM query_p AS qp))

AND

NOT
client.is_demo

AND

NOT
client.deleted

)

Select qp.client_id, (SELECT COUNT(0) FROM customers AS c WHERE (c.clientid
= qp.client_id) AND NOT c.deleted) AS client_count

FROM query_p AS qp

*Explain Analyze:*

CTE Scan on "query_p" "qp" (cost=0.01..1060.57 rows=1 width=8) (actual
time=4065.244..4065.246 rows=1 loops=1)

CTE query_p

-> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.002..0.003
rows=1 loops=1)

SubPlan 2

-> Aggregate (cost=1060.53..1060.54 rows=1 width=0) (actual
time=4065.229..4065.229 rows=1 loops=1)

-> Index Scan using "clientid_customers" on "customers" "c"
(cost=0.00..1059.01 rows=607 width=0) (actual time=9.105..4063.728
rows=2513 loops=1)

Index Cond: ("clientid" = "qp"."client_id")

Filter: (NOT "deleted")

Rows Removed by Filter: 1068

Total runtime: 4075.753 ms

Why a search for "client_id" is so slow??

*Table customers:*

Table "public.customers"

Column | Type |
Modifiers

------------------------+-----------------------------+-----------------------------------------------------------------

id | bigint | not null default
"nextval"('"customers_seq"'::"regclass")

clientid | bigint | not null default 0

name_first | character varying(80) | default
''::character varying

name_last | character varying(80) | default
''::character varying

company | character varying(255) | default
''::character varying

*Index clientid_customers:*

CREATE INDEX

clientid_customers

ON

customers

(

"clientid"

);

Thanks!

Patrick

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jan de Visser 2017-01-10 02:30:39 Re: Slow index scan - Pgsql 9.2
Previous Message Vitaly Burovoy 2017-01-10 00:09:00 Re: Matching indexe for timestamp