From: | Daniel Blanch Bataller <daniel(dot)blanch(dot)bataller(at)gmail(dot)com> |
---|---|
To: | Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Eric Jiang <eric(at)doublemap(dot)com>, pgsql-performance(at)postgresql(dot)org, Eric Clark <eclark(at)doublemap(dot)com> |
Subject: | Re: Querying with multicolumn index |
Date: | 2016-12-11 06:04:45 |
Message-ID: | 36867AC4-DDD8-464E-A0F7-066B4C88300C@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Hi all,
Thomas is absolutely right, the distribution I synthetically made, had 6M records but very old, 9M old, as you can see it had to skip 9M records before finding a suitable record using time index.
EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM updates WHERE driver_id = 100 ORDER BY "time" DESC LIMIT 1;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.44..0.65 rows=1 width=36) (actual time=3827.807..3827.807 rows=1 loops=1)
Buffers: shared hit=24592 read=99594 written=659
-> Index Scan Backward using updates_time_idx on updates (cost=0.44..1284780.53 rows=6064800 width=36) (actual time=3827.805..3827.805 rows=1 loops=1)
Filter: (driver_id = 100)
Rows Removed by Filter: 9000000
Buffers: shared hit=24592 read=99594 written=659
Planning time: 0.159 ms
Execution time: 3827.846 ms
(8 rows)
Here you have my tests where I was able to reproduce the problem using default settings on 9.6, 9.5 and 9.3. 9.6 and 9.5 choose the wrong index, while 9.3 didn’t. (update: 9.5 didn’t fail last time)
Attachment | Content-Type | Size |
---|---|---|
test_bad_index_choice.sql | application/octet-stream | 1.4 KB |
bad_idx_choice.9.6.out | application/octet-stream | 4.7 KB |
bad_idx_choice.9.5.out | application/octet-stream | 5.1 KB |
bad_idx_choice.9.3.out | application/octet-stream | 5.0 KB |
unknown_filename | text/plain | 1.4 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | ProPAAS DBA | 2016-12-13 20:16:14 | Isolation of tx logs on VMware |
Previous Message | Eric Jiang | 2016-12-11 02:08:48 | Re: Querying with multicolumn index |