@@ -299,48 +299,48 @@ SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c
299
299
TRUNCATE TABLE ndistinct;
300
300
-- under-estimates when using only per-column statistics
301
301
INSERT INTO ndistinct (a, b, c, filler1)
302
- SELECT mod(i,50 ), mod(i,51 ), mod(i,32 ),
303
- cash_words(mod(i,33 )::int::money)
304
- FROM generate_series(1,5000 ) s(i);
302
+ SELECT mod(i,13 ), mod(i,17 ), mod(i,19 ),
303
+ cash_words(mod(i,23 )::int::money)
304
+ FROM generate_series(1,1000 ) s(i);
305
305
ANALYZE ndistinct;
306
306
SELECT s.stxkind, d.stxdndistinct
307
307
FROM pg_statistic_ext s, pg_statistic_ext_data d
308
308
WHERE s.stxrelid = 'ndistinct'::regclass
309
309
AND d.stxoid = s.oid;
310
- stxkind | stxdndistinct
311
- ---------+------------------------------------------------------------
312
- {d,f,m} | {"3, 4": 2550 , "3, 6": 800 , "4, 6": 1632 , "3, 4, 6": 5000 }
310
+ stxkind | stxdndistinct
311
+ ---------+----------------------------------------------------------
312
+ {d,f,m} | {"3, 4": 221 , "3, 6": 247 , "4, 6": 323 , "3, 4, 6": 1000 }
313
313
(1 row)
314
314
315
315
-- correct estimates
316
316
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b');
317
317
estimated | actual
318
318
-----------+--------
319
- 2550 | 2550
319
+ 221 | 221
320
320
(1 row)
321
321
322
322
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c');
323
323
estimated | actual
324
324
-----------+--------
325
- 5000 | 5000
325
+ 1000 | 1000
326
326
(1 row)
327
327
328
328
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d');
329
329
estimated | actual
330
330
-----------+--------
331
- 5000 | 5000
331
+ 1000 | 1000
332
332
(1 row)
333
333
334
334
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d');
335
335
estimated | actual
336
336
-----------+--------
337
- 1632 | 1632
337
+ 323 | 323
338
338
(1 row)
339
339
340
340
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, d');
341
341
estimated | actual
342
342
-----------+--------
343
- 500 | 50
343
+ 200 | 13
344
344
(1 row)
345
345
346
346
DROP STATISTICS s10;
@@ -356,31 +356,31 @@ SELECT s.stxkind, d.stxdndistinct
356
356
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b');
357
357
estimated | actual
358
358
-----------+--------
359
- 500 | 2550
359
+ 100 | 221
360
360
(1 row)
361
361
362
362
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c');
363
363
estimated | actual
364
364
-----------+--------
365
- 500 | 5000
365
+ 100 | 1000
366
366
(1 row)
367
367
368
368
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d');
369
369
estimated | actual
370
370
-----------+--------
371
- 500 | 5000
371
+ 200 | 1000
372
372
(1 row)
373
373
374
374
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d');
375
375
estimated | actual
376
376
-----------+--------
377
- 500 | 1632
377
+ 200 | 323
378
378
(1 row)
379
379
380
380
SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, d');
381
381
estimated | actual
382
382
-----------+--------
383
- 500 | 50
383
+ 200 | 13
384
384
(1 row)
385
385
386
386
-- functional dependencies tests
@@ -398,18 +398,18 @@ CREATE INDEX fdeps_ab_idx ON functional_dependencies (a, b);
398
398
CREATE INDEX fdeps_abc_idx ON functional_dependencies (a, b, c);
399
399
-- random data (no functional dependencies)
400
400
INSERT INTO functional_dependencies (a, b, c, filler1)
401
- SELECT mod(i, 23 ), mod(i, 29 ), mod(i, 31 ), i FROM generate_series(1,5000 ) s(i);
401
+ SELECT mod(i, 5 ), mod(i, 7 ), mod(i, 11 ), i FROM generate_series(1,1000 ) s(i);
402
402
ANALYZE functional_dependencies;
403
403
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''');
404
404
estimated | actual
405
405
-----------+--------
406
- 8 | 8
406
+ 29 | 29
407
407
(1 row)
408
408
409
409
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1');
410
410
estimated | actual
411
411
-----------+--------
412
- 1 | 1
412
+ 3 | 3
413
413
(1 row)
414
414
415
415
-- create statistics
@@ -418,13 +418,13 @@ ANALYZE functional_dependencies;
418
418
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''');
419
419
estimated | actual
420
420
-----------+--------
421
- 8 | 8
421
+ 29 | 29
422
422
(1 row)
423
423
424
424
SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1');
425
425
estimated | actual
426
426
-----------+--------
427
- 1 | 1
427
+ 3 | 3
428
428
(1 row)
429
429
430
430
-- a => b, a => c, b => c
0 commit comments