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

Commit 0936d1b

Browse files
committed
Still another try at stabilizing stats_ext test results.
The stats_ext test is not expecting that autovacuum will touch any of its tables; an expectation falsified by commit b07642d. Although I'm suspicious that there's something else going on that makes extended stats estimates not 100% reproducible, it's pretty easy to demonstrate that there are places in this test that fail if an autovacuum updates the table's stats unexpectedly. Hence, revert the band-aid changes made by 2dc16ef and 24566b3 in favor of summarily disabling autovacuum for all the tables that this test checks estimated rowcounts for. Also remove an evidently obsolete comment at the head of the test. Discussion: https://postgr.es/m/15012.1585623298@sss.pgh.pa.us
1 parent 69360b3 commit 0936d1b

File tree

2 files changed

+65
-44
lines changed

2 files changed

+65
-44
lines changed

src/test/regress/expected/stats_ext.out

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
-- Generic extended statistics support
2-
-- We will be checking execution plans without/with statistics, so
3-
-- let's make sure we get simple non-parallel plans. Also set the
4-
-- work_mem low so that we can use small amounts of data.
2+
--
3+
-- Note: tables for which we check estimated row counts should be created
4+
-- with autovacuum_enabled = off, so that we don't have unstable results
5+
-- from auto-analyze happening when we didn't expect it.
6+
--
57
-- check the number of estimated/actual rows in the top node
68
create function check_estimated_rows(text) returns table (estimated int, actual int)
79
language plpgsql as
@@ -184,7 +186,8 @@ CREATE TABLE ndistinct (
184186
filler3 DATE,
185187
c INT,
186188
d INT
187-
);
189+
)
190+
WITH (autovacuum_enabled = off);
188191
-- over-estimates when using only per-column statistics
189192
INSERT INTO ndistinct (a, b, c, filler1)
190193
SELECT i/100, i/100, i/100, cash_words((i/100)::money)
@@ -279,7 +282,7 @@ INSERT INTO ndistinct (a, b, c, filler1)
279282
SELECT mod(i,50), mod(i,51), mod(i,32),
280283
cash_words(mod(i,33)::int::money)
281284
FROM generate_series(1,5000) s(i);
282-
VACUUM (ANALYZE) ndistinct;
285+
ANALYZE ndistinct;
283286
SELECT s.stxkind, d.stxdndistinct
284287
FROM pg_statistic_ext s, pg_statistic_ext_data d
285288
WHERE s.stxrelid = 'ndistinct'::regclass
@@ -369,13 +372,14 @@ CREATE TABLE functional_dependencies (
369372
filler3 DATE,
370373
c INT,
371374
d TEXT
372-
);
375+
)
376+
WITH (autovacuum_enabled = off);
373377
CREATE INDEX fdeps_ab_idx ON functional_dependencies (a, b);
374378
CREATE INDEX fdeps_abc_idx ON functional_dependencies (a, b, c);
375379
-- random data (no functional dependencies)
376380
INSERT INTO functional_dependencies (a, b, c, filler1)
377381
SELECT mod(i, 23), mod(i, 29), mod(i, 31), i FROM generate_series(1,5000) s(i);
378-
VACUUM (ANALYZE) functional_dependencies;
382+
ANALYZE functional_dependencies;
379383
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''');
380384
estimated | actual
381385
-----------+--------
@@ -408,7 +412,7 @@ TRUNCATE functional_dependencies;
408412
DROP STATISTICS func_deps_stat;
409413
INSERT INTO functional_dependencies (a, b, c, filler1)
410414
SELECT mod(i,100), mod(i,50), mod(i,25), i FROM generate_series(1,5000) s(i);
411-
VACUUM (ANALYZE) functional_dependencies;
415+
ANALYZE functional_dependencies;
412416
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''');
413417
estimated | actual
414418
-----------+--------
@@ -741,7 +745,7 @@ SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE
741745
25 | 50
742746
(1 row)
743747

744-
VACUUM (ANALYZE) functional_dependencies;
748+
ANALYZE functional_dependencies;
745749
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1');
746750
estimated | actual
747751
-----------+--------
@@ -754,7 +758,8 @@ CREATE TABLE functional_dependencies_multi (
754758
b INTEGER,
755759
c INTEGER,
756760
d INTEGER
757-
);
761+
)
762+
WITH (autovacuum_enabled = off);
758763
INSERT INTO functional_dependencies_multi (a, b, c, d)
759764
SELECT
760765
mod(i,7),
@@ -838,11 +843,12 @@ CREATE TABLE mcv_lists (
838843
filler3 DATE,
839844
c INT,
840845
d TEXT
841-
);
846+
)
847+
WITH (autovacuum_enabled = off);
842848
-- random data (no MCV list)
843849
INSERT INTO mcv_lists (a, b, c, filler1)
844850
SELECT mod(i,37), mod(i,41), mod(i,43), mod(i,47) FROM generate_series(1,5000) s(i);
845-
VACUUM (ANALYZE) mcv_lists;
851+
ANALYZE mcv_lists;
846852
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''');
847853
estimated | actual
848854
-----------+--------
@@ -875,7 +881,7 @@ TRUNCATE mcv_lists;
875881
DROP STATISTICS mcv_lists_stats;
876882
INSERT INTO mcv_lists (a, b, c, filler1)
877883
SELECT mod(i,100), mod(i,50), mod(i,25), i FROM generate_series(1,5000) s(i);
878-
VACUUM (ANALYZE) mcv_lists;
884+
ANALYZE mcv_lists;
879885
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''');
880886
estimated | actual
881887
-----------+--------
@@ -1175,7 +1181,7 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b =
11751181
1 | 50
11761182
(1 row)
11771183

1178-
VACUUM (ANALYZE) mcv_lists;
1184+
ANALYZE mcv_lists;
11791185
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''');
11801186
estimated | actual
11811187
-----------+--------
@@ -1192,7 +1198,7 @@ INSERT INTO mcv_lists (a, b, c, filler1)
11921198
(CASE WHEN mod(i,25) = 1 THEN NULL ELSE mod(i,25) END),
11931199
i
11941200
FROM generate_series(1,5000) s(i);
1195-
VACUUM (ANALYZE) mcv_lists;
1201+
ANALYZE mcv_lists;
11961202
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL');
11971203
estimated | actual
11981204
-----------+--------
@@ -1259,7 +1265,7 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IN (0, 1) AN
12591265
-- test pg_mcv_list_items with a very simple (single item) MCV list
12601266
TRUNCATE mcv_lists;
12611267
INSERT INTO mcv_lists (a, b, c) SELECT 1, 2, 3 FROM generate_series(1,1000) s(i);
1262-
VACUUM (ANALYZE) mcv_lists;
1268+
ANALYZE mcv_lists;
12631269
SELECT m.*
12641270
FROM pg_statistic_ext s, pg_statistic_ext_data d,
12651271
pg_mcv_list_items(d.stxdmcv) m
@@ -1280,7 +1286,7 @@ INSERT INTO mcv_lists (a, b, c, d)
12801286
(CASE WHEN mod(i,2) = 0 THEN NULL ELSE 0 END),
12811287
(CASE WHEN mod(i,2) = 0 THEN NULL ELSE 'x' END)
12821288
FROM generate_series(1,5000) s(i);
1283-
VACUUM (ANALYZE) mcv_lists;
1289+
ANALYZE mcv_lists;
12841290
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE b = ''x'' OR d = ''x''');
12851291
estimated | actual
12861292
-----------+--------
@@ -1337,7 +1343,8 @@ CREATE TABLE mcv_lists_uuid (
13371343
a UUID,
13381344
b UUID,
13391345
c UUID
1340-
);
1346+
)
1347+
WITH (autovacuum_enabled = off);
13411348
INSERT INTO mcv_lists_uuid (a, b, c)
13421349
SELECT
13431350
md5(mod(i,100)::text)::uuid,
@@ -1378,7 +1385,8 @@ CREATE TABLE mcv_lists_arrays (
13781385
a TEXT[],
13791386
b NUMERIC[],
13801387
c INT[]
1381-
);
1388+
)
1389+
WITH (autovacuum_enabled = off);
13821390
INSERT INTO mcv_lists_arrays (a, b, c)
13831391
SELECT
13841392
ARRAY[md5((i/100)::text), md5((i/100-1)::text), md5((i/100+1)::text)],
@@ -1393,12 +1401,13 @@ CREATE TABLE mcv_lists_bool (
13931401
a BOOL,
13941402
b BOOL,
13951403
c BOOL
1396-
);
1404+
)
1405+
WITH (autovacuum_enabled = off);
13971406
INSERT INTO mcv_lists_bool (a, b, c)
13981407
SELECT
13991408
(mod(i,2) = 0), (mod(i,4) = 0), (mod(i,8) = 0)
14001409
FROM generate_series(1,10000) s(i);
1401-
VACUUM (ANALYZE) mcv_lists_bool;
1410+
ANALYZE mcv_lists_bool;
14021411
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE a AND b AND c');
14031412
estimated | actual
14041413
-----------+--------
@@ -1456,7 +1465,8 @@ CREATE TABLE mcv_lists_multi (
14561465
b INTEGER,
14571466
c INTEGER,
14581467
d INTEGER
1459-
);
1468+
)
1469+
WITH (autovacuum_enabled = off);
14601470
INSERT INTO mcv_lists_multi (a, b, c, d)
14611471
SELECT
14621472
mod(i,5),

src/test/regress/sql/stats_ext.sql

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
-- Generic extended statistics support
22

3-
-- We will be checking execution plans without/with statistics, so
4-
-- let's make sure we get simple non-parallel plans. Also set the
5-
-- work_mem low so that we can use small amounts of data.
3+
--
4+
-- Note: tables for which we check estimated row counts should be created
5+
-- with autovacuum_enabled = off, so that we don't have unstable results
6+
-- from auto-analyze happening when we didn't expect it.
7+
--
68

79
-- check the number of estimated/actual rows in the top node
810
create function check_estimated_rows(text) returns table (estimated int, actual int)
@@ -137,7 +139,8 @@ CREATE TABLE ndistinct (
137139
filler3 DATE,
138140
c INT,
139141
d INT
140-
);
142+
)
143+
WITH (autovacuum_enabled = off);
141144

142145
-- over-estimates when using only per-column statistics
143146
INSERT INTO ndistinct (a, b, c, filler1)
@@ -191,7 +194,7 @@ INSERT INTO ndistinct (a, b, c, filler1)
191194
cash_words(mod(i,33)::int::money)
192195
FROM generate_series(1,5000) s(i);
193196

194-
VACUUM (ANALYZE) ndistinct;
197+
ANALYZE ndistinct;
195198

196199
SELECT s.stxkind, d.stxdndistinct
197200
FROM pg_statistic_ext s, pg_statistic_ext_data d
@@ -236,7 +239,8 @@ CREATE TABLE functional_dependencies (
236239
filler3 DATE,
237240
c INT,
238241
d TEXT
239-
);
242+
)
243+
WITH (autovacuum_enabled = off);
240244

241245
CREATE INDEX fdeps_ab_idx ON functional_dependencies (a, b);
242246
CREATE INDEX fdeps_abc_idx ON functional_dependencies (a, b, c);
@@ -245,7 +249,7 @@ CREATE INDEX fdeps_abc_idx ON functional_dependencies (a, b, c);
245249
INSERT INTO functional_dependencies (a, b, c, filler1)
246250
SELECT mod(i, 23), mod(i, 29), mod(i, 31), i FROM generate_series(1,5000) s(i);
247251

248-
VACUUM (ANALYZE) functional_dependencies;
252+
ANALYZE functional_dependencies;
249253

250254
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''');
251255

@@ -267,7 +271,7 @@ DROP STATISTICS func_deps_stat;
267271
INSERT INTO functional_dependencies (a, b, c, filler1)
268272
SELECT mod(i,100), mod(i,50), mod(i,25), i FROM generate_series(1,5000) s(i);
269273

270-
VACUUM (ANALYZE) functional_dependencies;
274+
ANALYZE functional_dependencies;
271275

272276
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''');
273277

@@ -396,7 +400,7 @@ ALTER TABLE functional_dependencies ALTER COLUMN c TYPE numeric;
396400

397401
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1');
398402

399-
VACUUM (ANALYZE) functional_dependencies;
403+
ANALYZE functional_dependencies;
400404

401405
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1');
402406

@@ -406,7 +410,8 @@ CREATE TABLE functional_dependencies_multi (
406410
b INTEGER,
407411
c INTEGER,
408412
d INTEGER
409-
);
413+
)
414+
WITH (autovacuum_enabled = off);
410415

411416
INSERT INTO functional_dependencies_multi (a, b, c, d)
412417
SELECT
@@ -448,13 +453,14 @@ CREATE TABLE mcv_lists (
448453
filler3 DATE,
449454
c INT,
450455
d TEXT
451-
);
456+
)
457+
WITH (autovacuum_enabled = off);
452458

453459
-- random data (no MCV list)
454460
INSERT INTO mcv_lists (a, b, c, filler1)
455461
SELECT mod(i,37), mod(i,41), mod(i,43), mod(i,47) FROM generate_series(1,5000) s(i);
456462

457-
VACUUM (ANALYZE) mcv_lists;
463+
ANALYZE mcv_lists;
458464

459465
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''');
460466

@@ -476,7 +482,7 @@ DROP STATISTICS mcv_lists_stats;
476482
INSERT INTO mcv_lists (a, b, c, filler1)
477483
SELECT mod(i,100), mod(i,50), mod(i,25), i FROM generate_series(1,5000) s(i);
478484

479-
VACUUM (ANALYZE) mcv_lists;
485+
ANALYZE mcv_lists;
480486

481487
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''');
482488

@@ -589,7 +595,7 @@ ALTER TABLE mcv_lists ALTER COLUMN c TYPE numeric;
589595

590596
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''');
591597

592-
VACUUM (ANALYZE) mcv_lists;
598+
ANALYZE mcv_lists;
593599

594600
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a = 1 AND b = ''1''');
595601

@@ -605,7 +611,7 @@ INSERT INTO mcv_lists (a, b, c, filler1)
605611
i
606612
FROM generate_series(1,5000) s(i);
607613

608-
VACUUM (ANALYZE) mcv_lists;
614+
ANALYZE mcv_lists;
609615

610616
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IS NULL AND b IS NULL');
611617

@@ -635,7 +641,8 @@ SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE a IN (0, 1) AN
635641
-- test pg_mcv_list_items with a very simple (single item) MCV list
636642
TRUNCATE mcv_lists;
637643
INSERT INTO mcv_lists (a, b, c) SELECT 1, 2, 3 FROM generate_series(1,1000) s(i);
638-
VACUUM (ANALYZE) mcv_lists;
644+
ANALYZE mcv_lists;
645+
639646
SELECT m.*
640647
FROM pg_statistic_ext s, pg_statistic_ext_data d,
641648
pg_mcv_list_items(d.stxdmcv) m
@@ -654,7 +661,7 @@ INSERT INTO mcv_lists (a, b, c, d)
654661
(CASE WHEN mod(i,2) = 0 THEN NULL ELSE 'x' END)
655662
FROM generate_series(1,5000) s(i);
656663

657-
VACUUM (ANALYZE) mcv_lists;
664+
ANALYZE mcv_lists;
658665

659666
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists WHERE b = ''x'' OR d = ''x''');
660667

@@ -685,7 +692,8 @@ CREATE TABLE mcv_lists_uuid (
685692
a UUID,
686693
b UUID,
687694
c UUID
688-
);
695+
)
696+
WITH (autovacuum_enabled = off);
689697

690698
INSERT INTO mcv_lists_uuid (a, b, c)
691699
SELECT
@@ -716,7 +724,8 @@ CREATE TABLE mcv_lists_arrays (
716724
a TEXT[],
717725
b NUMERIC[],
718726
c INT[]
719-
);
727+
)
728+
WITH (autovacuum_enabled = off);
720729

721730
INSERT INTO mcv_lists_arrays (a, b, c)
722731
SELECT
@@ -735,14 +744,15 @@ CREATE TABLE mcv_lists_bool (
735744
a BOOL,
736745
b BOOL,
737746
c BOOL
738-
);
747+
)
748+
WITH (autovacuum_enabled = off);
739749

740750
INSERT INTO mcv_lists_bool (a, b, c)
741751
SELECT
742752
(mod(i,2) = 0), (mod(i,4) = 0), (mod(i,8) = 0)
743753
FROM generate_series(1,10000) s(i);
744754

745-
VACUUM (ANALYZE) mcv_lists_bool;
755+
ANALYZE mcv_lists_bool;
746756

747757
SELECT * FROM check_estimated_rows('SELECT * FROM mcv_lists_bool WHERE a AND b AND c');
748758

@@ -771,7 +781,8 @@ CREATE TABLE mcv_lists_multi (
771781
b INTEGER,
772782
c INTEGER,
773783
d INTEGER
774-
);
784+
)
785+
WITH (autovacuum_enabled = off);
775786

776787
INSERT INTO mcv_lists_multi (a, b, c, d)
777788
SELECT

0 commit comments

Comments
 (0)