Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 603b732

Browse files
committed
small opt issue fixed, test added
1 parent 3b30a49 commit 603b732

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

expected/altorder.out

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ SELECT id, d, d |=> '2016-05-16 14:21:25' FROM atsts WHERE t @@ 'wr&qh' ORDER BY
7373
457 | Fri May 20 20:21:22.326724 2016 | 367197.326724
7474
(5 rows)
7575

76+
SELECT count(*) FROM atsts WHERE d < '2016-05-16 14:21:25';
77+
count
78+
-------
79+
357
80+
(1 row)
81+
82+
SELECT count(*) FROM atsts WHERE d > '2016-05-16 14:21:25';
83+
count
84+
-------
85+
153
86+
(1 row)
87+
7688
RESET enable_indexscan;
7789
RESET enable_indexonlyscan;
7890
RESET enable_bitmapscan;
@@ -124,6 +136,40 @@ SELECT count(*) FROM atsts WHERE t @@ '(eq|yt)&(wr|qh)';
124136
39
125137
(1 row)
126138

139+
EXPLAIN (costs off)
140+
SELECT count(*) FROM atsts WHERE d < '2016-05-16 14:21:25';
141+
QUERY PLAN
142+
-----------------------------------------------------------------------------------------
143+
Aggregate
144+
-> Bitmap Heap Scan on atsts
145+
Recheck Cond: (d < 'Mon May 16 14:21:25 2016'::timestamp without time zone)
146+
-> Bitmap Index Scan on atsts_idx
147+
Index Cond: (d < 'Mon May 16 14:21:25 2016'::timestamp without time zone)
148+
(5 rows)
149+
150+
SELECT count(*) FROM atsts WHERE d < '2016-05-16 14:21:25';
151+
count
152+
-------
153+
357
154+
(1 row)
155+
156+
EXPLAIN (costs off)
157+
SELECT count(*) FROM atsts WHERE d > '2016-05-16 14:21:25';
158+
QUERY PLAN
159+
-----------------------------------------------------------------------------------------
160+
Aggregate
161+
-> Bitmap Heap Scan on atsts
162+
Recheck Cond: (d > 'Mon May 16 14:21:25 2016'::timestamp without time zone)
163+
-> Bitmap Index Scan on atsts_idx
164+
Index Cond: (d > 'Mon May 16 14:21:25 2016'::timestamp without time zone)
165+
(5 rows)
166+
167+
SELECT count(*) FROM atsts WHERE d > '2016-05-16 14:21:25';
168+
count
169+
-------
170+
153
171+
(1 row)
172+
127173
EXPLAIN (costs off)
128174
SELECT id, d, d <=> '2016-05-16 14:21:25' FROM atsts WHERE t @@ 'wr&qh' ORDER BY d <=> '2016-05-16 14:21:25' LIMIT 5;
129175
QUERY PLAN

rumbulk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ rumInsertBAEntry(BuildAccumulator *accum,
182182
* by setting shouldSort we prevent incorrect comparison in
183183
* rumCombineData()
184184
*/
185-
ea->shouldSort = accum->rumstate->useAlternativeOrder;
185+
ea->shouldSort = (accum->rumstate->useAlternativeOrder &&
186+
attnum == accum->rumstate->attrnAddToColumn);
186187
ea->list = (RumKey *) palloc(sizeof(RumKey) * DEF_NPTR);
187188
ea->list[0].iptr = *heapptr;
188189
ea->list[0].addInfo = addInfo;
@@ -300,7 +301,8 @@ rumGetBAEntry(BuildAccumulator *accum,
300301

301302
if (entry->count > 1)
302303
{
303-
if (accum->rumstate->useAlternativeOrder)
304+
if (accum->rumstate->useAlternativeOrder &&
305+
entry->attnum == accum->rumstate->attrnAddToColumn)
304306
qsort_arg(list, entry->count, sizeof(RumKey),
305307
qsortCompareRumKey, accum->rumstate);
306308
else if (entry->shouldSort)

sql/altorder.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ SELECT id, d, d <=> '2016-05-16 14:21:25' FROM atsts WHERE t @@ 'wr&qh' ORDER BY
2424
SELECT id, d, d <=| '2016-05-16 14:21:25' FROM atsts WHERE t @@ 'wr&qh' ORDER BY d <=| '2016-05-16 14:21:25' LIMIT 5;
2525
SELECT id, d, d |=> '2016-05-16 14:21:25' FROM atsts WHERE t @@ 'wr&qh' ORDER BY d |=> '2016-05-16 14:21:25' LIMIT 5;
2626

27+
SELECT count(*) FROM atsts WHERE d < '2016-05-16 14:21:25';
28+
SELECT count(*) FROM atsts WHERE d > '2016-05-16 14:21:25';
29+
2730

2831
RESET enable_indexscan;
2932
RESET enable_indexonlyscan;
@@ -39,6 +42,14 @@ SELECT count(*) FROM atsts WHERE t @@ 'eq|yt';
3942
SELECT count(*) FROM atsts WHERE t @@ '(eq&yt)|(wr&qh)';
4043
SELECT count(*) FROM atsts WHERE t @@ '(eq|yt)&(wr|qh)';
4144

45+
46+
EXPLAIN (costs off)
47+
SELECT count(*) FROM atsts WHERE d < '2016-05-16 14:21:25';
48+
SELECT count(*) FROM atsts WHERE d < '2016-05-16 14:21:25';
49+
EXPLAIN (costs off)
50+
SELECT count(*) FROM atsts WHERE d > '2016-05-16 14:21:25';
51+
SELECT count(*) FROM atsts WHERE d > '2016-05-16 14:21:25';
52+
4253
EXPLAIN (costs off)
4354
SELECT id, d, d <=> '2016-05-16 14:21:25' FROM atsts WHERE t @@ 'wr&qh' ORDER BY d <=> '2016-05-16 14:21:25' LIMIT 5;
4455
SELECT id, d, d <=> '2016-05-16 14:21:25' FROM atsts WHERE t @@ 'wr&qh' ORDER BY d <=> '2016-05-16 14:21:25' LIMIT 5;

0 commit comments

Comments
 (0)