@@ -299,48 +299,48 @@ SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c
299299TRUNCATE TABLE ndistinct;
300300-- under-estimates when using only per-column statistics
301301INSERT 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);
305305ANALYZE ndistinct;
306306SELECT s.stxkind, d.stxdndistinct
307307 FROM pg_statistic_ext s, pg_statistic_ext_data d
308308 WHERE s.stxrelid = 'ndistinct'::regclass
309309 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 }
313313(1 row)
314314
315315-- correct estimates
316316SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b');
317317 estimated | actual
318318-----------+--------
319- 2550 |2550
319+ 221 | 221
320320(1 row)
321321
322322SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c');
323323 estimated | actual
324324-----------+--------
325- 5000 |5000
325+ 1000 |1000
326326(1 row)
327327
328328SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d');
329329 estimated | actual
330330-----------+--------
331- 5000 |5000
331+ 1000 |1000
332332(1 row)
333333
334334SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d');
335335 estimated | actual
336336-----------+--------
337- 1632 |1632
337+ 323 | 323
338338(1 row)
339339
340340SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, d');
341341 estimated | actual
342342-----------+--------
343- 500 |50
343+ 200 |13
344344(1 row)
345345
346346DROP STATISTICS s10;
@@ -356,31 +356,31 @@ SELECT s.stxkind, d.stxdndistinct
356356SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b');
357357 estimated | actual
358358-----------+--------
359- 500 |2550
359+ 100 | 221
360360(1 row)
361361
362362SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c');
363363 estimated | actual
364364-----------+--------
365- 500 |5000
365+ 100 |1000
366366(1 row)
367367
368368SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, b, c, d');
369369 estimated | actual
370370-----------+--------
371- 500 |5000
371+ 200 |1000
372372(1 row)
373373
374374SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY b, c, d');
375375 estimated | actual
376376-----------+--------
377- 500 |1632
377+ 200 | 323
378378(1 row)
379379
380380SELECT * FROM check_estimated_rows('SELECT COUNT(*) FROM ndistinct GROUP BY a, d');
381381 estimated | actual
382382-----------+--------
383- 500 |50
383+ 200 |13
384384(1 row)
385385
386386-- functional dependencies tests
@@ -398,18 +398,18 @@ CREATE INDEX fdeps_ab_idx ON functional_dependencies (a, b);
398398CREATE INDEX fdeps_abc_idx ON functional_dependencies (a, b, c);
399399-- random data (no functional dependencies)
400400INSERT 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);
402402ANALYZE functional_dependencies;
403403SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''');
404404 estimated | actual
405405-----------+--------
406- 8 | 8
406+ 29 |29
407407(1 row)
408408
409409SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1');
410410 estimated | actual
411411-----------+--------
412- 1 |1
412+ 3 |3
413413(1 row)
414414
415415-- create statistics
@@ -418,13 +418,13 @@ ANALYZE functional_dependencies;
418418SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1''');
419419 estimated | actual
420420-----------+--------
421- 8 | 8
421+ 29 |29
422422(1 row)
423423
424424SELECT * FROM check_estimated_rows('SELECT * FROM functional_dependencies WHERE a = 1 AND b = ''1'' AND c = 1');
425425 estimated | actual
426426-----------+--------
427- 1 |1
427+ 3 |3
428428(1 row)
429429
430430-- a => b, a => c, b => c