Postgresql very slow query -


Why does this query run very slowly? Others are fine indexes are good i think Select "CIID" as "c_" from "e_inst" as "e_inst" group as "c_" by

  "e_inst" "e_inst" "Si_id" command "E_inst" "Si_id" ASC Nullest   

query scheme:

  sort (cost = 12221.87..12221.90 rows = 68 width = 4) (real time = 1115.377 ..1115.433 rows = 81 loops = 1) Sort key: CIID Sort Meth: QuickSource Memory: 28KB - & gt; Hash aggregate (cost = 12221.25..12221.45 rows = 68 width = 4) (real time = 1115.198..1115.261 rows = 81 loops = 1) - & gt; Seac scan on e-int (cost = 0.00..11920.07 rows = 602357 width = 4) (real time = 0.021..611.570 rows = 602357 loop = 1) Total runtime: 1115.538 ms   

Create table and index:

  create table e_inst (id not integer, tap, ip numeric, g character different, changing referer character, proc integer, loke_id integer, top_id integer, si_id integer, Kop integer, counting integer, made integer, modified integer, timepap full Nk, count-working characters different, the character of the country (3), information changing characters); Create Index "Top Announce" e_inst UST btree (built, top_id); Create an index "procEnhance" e_inst (created, proc) on UST btree; Create an index "countryEnhance" use e_install btree (created, country); Index "created e" create e_inst btree (created); Optional table e_inst CLUSTER "created e"; Create index "lokeE" e_inst UST btree (loke_id); Create Index "Lock Enhance" e_inst UST btree (built, lock_id); Create e-Institute UTTING BTIRI (CIIID) on Index "CIE"; Create Index "CINs" e-Instant Utting BTRI (Created, CIID); Create Index "Cop Enhance" e_inst UST btree (created, cop);    

Indexes are not being used by a query that processes the entire table

The fact is that you are retrieving the and processing 600k records, it is really effective in just a second.

Now in this case, you are trying to remove 81 specific values ​​from 600 records. What you might want to do is create a recursive query, as if it receives a line 81 times it may be fast but there is no guarantee usually I use these I am where very few lines are returned. However here is an example:

  as well as recommended sparse_scan (SELECT min (si_id) si_id as e_inst UNION ALL SELECT min (si_id) as si_id FROM e_inst JOIN (max. Choose (si_id) from final form sparse_scan) S WHERE s.last & lt; si_id) SELECT SI_ID as c0 to sparse_scan;   

Note that this 81 index replaces a sequential scan with scan.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -