Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcec5501

Browse files
committed
Add a regression test case to improve code coverage for tuplesort.
Test the external-sort code path in CLUSTER for two different scenarios:multiple-pass external sorting, and the best case for replacementselection, where only one run is produced, so that no merge is required.This test would have caught the bug fixed in commit1b0fc85, atleast when run with valgrind enabled.In passing, add a short-circuit test in plan_cluster_use_sort() to makedead certain that it selects sorting when enable_indexscan is off. Asthings stand, that would happen anyway, but it seems like good futureproofing for this test.Peter GeogheganDiscussion: <CAM3SWZSgxehDkDMq1FdiW2A0Dxc79wH0hz1x-TnGy=1BXEL+nw@mail.gmail.com>
1 parent91c0eb5 commitcec5501

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

‎src/backend/optimizer/plan/planner.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5193,6 +5193,10 @@ plan_cluster_use_sort(Oid tableOid, Oid indexOid)
51935193
IndexPath*indexScanPath;
51945194
ListCell*lc;
51955195

5196+
/* We can short-circuit the cost comparison if indexscans are disabled */
5197+
if (!enable_indexscan)
5198+
return true;/* use sort */
5199+
51965200
/* Set up mostly-dummy planner state */
51975201
query=makeNode(Query);
51985202
query->commandType=CMD_SELECT;

‎src/test/regress/expected/cluster.out

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,46 @@ select * from clstr_temp;
438438
(2 rows)
439439

440440
drop table clstr_temp;
441+
RESET SESSION AUTHORIZATION;
442+
-- Test CLUSTER with external tuplesorting
443+
create table clstr_4 as select * from tenk1;
444+
create index cluster_sort on clstr_4 (hundred, thousand, tenthous);
445+
-- ensure we don't use the index in CLUSTER nor the checking SELECTs
446+
set enable_indexscan = off;
447+
-- Use external sort that only ever uses quicksort to sort runs:
448+
set maintenance_work_mem = '1MB';
449+
set replacement_sort_tuples = 0;
450+
cluster clstr_4 using cluster_sort;
451+
select * from
452+
(select hundred, lag(hundred) over () as lhundred,
453+
thousand, lag(thousand) over () as lthousand,
454+
tenthous, lag(tenthous) over () as ltenthous from clstr_4) ss
455+
where row(hundred, thousand, tenthous) <= row(lhundred, lthousand, ltenthous);
456+
hundred | lhundred | thousand | lthousand | tenthous | ltenthous
457+
---------+----------+----------+-----------+----------+-----------
458+
(0 rows)
459+
460+
-- Replacement selection will now be forced. It should only produce a single
461+
-- run, due to the fact that input is found to be presorted:
462+
set replacement_sort_tuples = 150000;
463+
cluster clstr_4 using cluster_sort;
464+
select * from
465+
(select hundred, lag(hundred) over () as lhundred,
466+
thousand, lag(thousand) over () as lthousand,
467+
tenthous, lag(tenthous) over () as ltenthous from clstr_4) ss
468+
where row(hundred, thousand, tenthous) <= row(lhundred, lthousand, ltenthous);
469+
hundred | lhundred | thousand | lthousand | tenthous | ltenthous
470+
---------+----------+----------+-----------+----------+-----------
471+
(0 rows)
472+
473+
reset enable_indexscan;
474+
reset maintenance_work_mem;
475+
reset replacement_sort_tuples;
441476
-- clean up
442477
\c -
443478
DROP TABLE clustertest;
444479
DROP TABLE clstr_1;
445480
DROP TABLE clstr_2;
446481
DROP TABLE clstr_3;
482+
DROP TABLE clstr_4;
447483
DROP USER clstr_user;

‎src/test/regress/sql/cluster.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,44 @@ cluster clstr_temp using clstr_temp_pkey;
194194
select*from clstr_temp;
195195
droptable clstr_temp;
196196

197+
RESET SESSION AUTHORIZATION;
198+
199+
-- Test CLUSTER with external tuplesorting
200+
201+
createtableclstr_4asselect*from tenk1;
202+
createindexcluster_sorton clstr_4 (hundred, thousand, tenthous);
203+
-- ensure we don't use the index in CLUSTER nor the checking SELECTs
204+
set enable_indexscan= off;
205+
206+
-- Use external sort that only ever uses quicksort to sort runs:
207+
set maintenance_work_mem='1MB';
208+
set replacement_sort_tuples=0;
209+
cluster clstr_4 using cluster_sort;
210+
select*from
211+
(select hundred, lag(hundred) over ()as lhundred,
212+
thousand, lag(thousand) over ()as lthousand,
213+
tenthous, lag(tenthous) over ()as ltenthousfrom clstr_4) ss
214+
where row(hundred, thousand, tenthous)<= row(lhundred, lthousand, ltenthous);
215+
216+
-- Replacement selection will now be forced. It should only produce a single
217+
-- run, due to the fact that input is found to be presorted:
218+
set replacement_sort_tuples=150000;
219+
cluster clstr_4 using cluster_sort;
220+
select*from
221+
(select hundred, lag(hundred) over ()as lhundred,
222+
thousand, lag(thousand) over ()as lthousand,
223+
tenthous, lag(tenthous) over ()as ltenthousfrom clstr_4) ss
224+
where row(hundred, thousand, tenthous)<= row(lhundred, lthousand, ltenthous);
225+
226+
reset enable_indexscan;
227+
reset maintenance_work_mem;
228+
reset replacement_sort_tuples;
229+
197230
-- clean up
198231
\c-
199232
DROPTABLE clustertest;
200233
DROPTABLE clstr_1;
201234
DROPTABLE clstr_2;
202235
DROPTABLE clstr_3;
236+
DROPTABLE clstr_4;
203237
DROPUSER clstr_user;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp