https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
Tomas Vondra <tomas.vondra@2ndquadrant.com>
CREATE STATISTICS What is it for? Tomas Vondra - - PowerPoint PPT Presentation
pgconf.eu 2018 Lisbon, October 23-26, 2018 CREATE STATISTICS What is it for? Tomas Vondra <tomas.vondra@2ndquadrant.com> https://github.com/tvondra/create-statistics-talk https://www. 2ndQuadrant.com pgconf.eu 2018 Lisbon, October
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
Tomas Vondra <tomas.vondra@2ndquadrant.com>
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
– functional dependencies – ndistinct
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
C R E A T E T A B L E z i p _ c
e s ( p
t a l _ c
e V A R C H A R ( 2 ) , p l a c e _ n a m e V A R C H A R ( 1 8 ) , s t a t e _ n a m e V A R C H A R ( 1 ) , p r
i n c e _ n a m e V A R C H A R ( 1 ) , c
m u n i t y _ n a m e V A R C H A R ( 1 ) , l a t i t u d e R E A L , l
g i t u d e R E A L ) ; c a t c r e a t e
a b l e . s q l | p s q l t e s t c a t z i p
e s
t u g a l . c s v | p s q l t e s t
" c
y z i p _ c
e s f r
s t d i n "
t t p : / / d
n l
d . g e
a m e s .
g / e x p
t / z i p /
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T * F R O M z i p _ c
e s W H E R E p l a c e _ n a m e = ' L i s b
' ; Q U E R Y P L A N
e q S c a n
z i p _ c
e s ( c
t = . . . 4 8 6 . 7 6 r
s = 8 5 8 8 w i d t h = 5 6 ) ( a c t u a l r
s = 9 1 6 6 l
s = 1 ) F i l t e r : ( ( p l a c e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) R
s R e m
e d b y F i l t e r : 1 9 7 7 7 5
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
S E L E C T r e l t u p l e s , r e l p a g e s F R O M p g _ c l a s s W H E R E r e l n a m e = ' z i p _ c
e s ' ; r e l t u p l e s | r e l p a g e s
6 9 4 1 | 2 2 7 4
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 S E L E C T * F R O M p g _ s t a t s W H E R E t a b l e n a m e = ' z i p _ c
e s ' A N D a t t n a m e = ' p l a c e _ n a m e ' ;
c h e m a n a m e | p u b l i c t a b l e n a m e | z i p _ c
e s a t t n a m e | p l a c e _ n a m e . . . | . . . m
t _ c
m
_ v a l s | { L i s b
, P
t
" V i l a N
a d e G a i a " , M a i a , . . . } m
t _ c
m
_ f r e q s | { . 4 1 5 , . 2 6 3 3 3 , . 8 9 6 6 6 7 , . 8 9 3 3 3 3 , . . . } . . . | . . .
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T * F R O M z i p _ c
e s W H E R E p l a c e _ n a m e = ' L i s b
' ; Q U E R Y P L A N
e q S c a n
z i p _ c
e s ( c
t = . . . 4 8 6 . 7 6 r
s = 8 5 8 8 w i d t h = 5 6 ) ( a c t u a l r
s = 9 1 6 6 l
s = 1 ) r e l t u p l e s | 2 6 9 4 1 m
t _ c
m
_ v a l s | { L i s b
, … } m
t _ c
m
_ f r e q s | { . 4 1 5 , … } 2 6 9 4 1 * . 4 1 5 = 8 5 8 8 . 5 1 5
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T * F R O M z i p _ c
e s W H E R E s t a t e _ n a m e = ' L i s b
' ; Q U E R Y P L A N
e q S c a n
z i p _ c
e s ( c
t = . . . 4 8 6 . 7 6 r
s = 3 4 2 6 3 w i d t h = 5 6 ) ( a c t u a l r
s = 3 5 2 3 l
s = 1 ) r e l t u p l e s | 2 6 9 4 1 m
t _ c
m
_ v a l s | { L i s b
, … } m
t _ c
m
_ f r e q s | { . 1 6 5 5 6 7 , … } 2 6 9 4 1 * . 1 6 5 5 6 7 = 3 4 2 6 2 . 6
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T * F R O M z i p _ c
e s W H E R E p l a c e _ n a m e = ' L i s b
' A N D s t a t e _ n a m e = ' L i s b
' ; Q U E R Y P L A N
e q S c a n
z i p _ c
e s ( c
t = . . . 5 3 7 8 . 1 1 r
s = 1 4 2 2 w i d t h = 5 6 ) ( a c t u a l r
s = 9 1 6 5 l
s = 1 ) F i l t e r : ( ( ( p l a c e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) A N D ( ( s t a t e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) ) R
s R e m
e d b y F i l t e r : 1 9 7 7 7 6
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 S E L E C T * F R O M z i p _ c
e s W H E R E p l a c e _ n a m e = ' L i s b
' A N D s t a t e _ n a m e = ' L i s b
' ; P ( p l a c e _ n a m e = ' L i s b
' & c
n t y _ n a m e = ' L i s b
' ) = P ( p l a c e _ n a m e = ' L i s b
' ) * P ( s t a t e _ n a m e = ' L i s b
' ) = . 4 1 5 * . 1 6 5 5 6 7 = . 6 8 7 1 3 5 2 6 9 4 1 * . 6 8 7 1 3 5 = 1 4 2 1 . 8 9 8
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T * F R O M z i p _ c
e s W H E R E p l a c e _ n a m e = ' L i s b
' A N D s t a t e _ n a m e = ' L i s b
' ; Q U E R Y P L A N
e q S c a n
z i p _ c
e s ( c
t = . . . 5 3 7 8 . 1 1 r
s = 1 4 2 2 w i d t h = 5 6 ) ( a c t u a l r
s = 9 1 6 5 l
s = 1 ) F i l t e r : ( ( ( p l a c e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) A N D ( ( s t a t e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) ) R
s R e m
e d b y F i l t e r : 1 9 7 7 7 6
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T * F R O M z i p _ c
e s W H E R E p l a c e _ n a m e = ' L i s b
' A N D s t a t e _ n a m e ! = ' L i s b
' ; Q U E R Y P L A N
e q S c a n
z i p _ c
e s ( c
t = . . . 5 3 7 8 . 1 1 r
s = 7 1 6 6 w i d t h = 5 6 ) ( a c t u a l r
s = 1 l
s = 1 ) F i l t e r : ( ( ( s t a t e _ n a m e ) : : t e x t < > ' L i s b
' : : t e x t ) A N D ( ( p l a c e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) ) R
s R e m
e d b y F i l t e r : 2 6 9 4
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
– may result in wildly inaccurate estimates – both underestimates and overestimates
– poor scan choices (Seq Scan vs. Index Scan) – poor join choices (Nested Loop)
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 I n d e x S c a n u s i n g
d e r s _ c i t y _ i d x
d e r s ( c
t = . 2 8 . . 1 8 5 . 1 r
s = 9 w i d t h = 3 6 ) ( a c t u a l r
s = 1 2 2 4 8 2 3 7 l
s = 1 ) S e q S c a n u s i n g
d e r s ( c
t = . 1 3 . . 1 2 9 3 8 5 . 1 r
s = 1 2 2 4 8 2 3 7 w i d t h = 3 6 ) ( a c t u a l r
s = 9 l
s = 1 )
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
N e s t e d L
( … r
s = 9 … ) ( … r
s = 1 2 2 4 8 2 3 7 … )
I n d e x S c a n u s i n g
d e r s _ c i t y _ i d x
d e r s ( c
t = . 2 8 . . 1 8 5 . 1 r
s = 9 w i d t h = 3 6 ) ( a c t u a l r
s = 1 2 2 4 8 2 3 7 l
s = 1 ) . . .
I n d e x S c a n … ( … l
s = 1 2 2 4 8 2 3 7 )
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
N e s t e d L
( … r
s = 9 … ) ( … r
s = 1 2 2 4 8 2 3 7 … )
N e s t e d L
( … r
s = 9 … ) ( … r
s = 1 2 2 4 8 2 3 7 … )
N e s t e d L
( … r
s = 9 … ) ( … r
s = 1 2 2 4 8 2 3 7 … )
I n d e x S c a n u s i n g
d e r s _ c i t y _ i d x
d e r s ( c
t = . 2 8 . . 1 8 5 . 1 r
s = 9 w i d t h = 3 6 ) ( a c t u a l r
s = 1 2 2 4 8 2 3 7 l
s = 1 ) . . .
I n d e x S c a n … ( … l
s = 1 2 2 4 8 2 3 7 )
I n d e x S c a n … ( … l
s = 1 2 2 4 8 2 3 7 )
I n d e x S c a n … ( … l
s = 1 2 2 4 8 2 3 7 )
I n d e x S c a n … ( … l
s = 1 2 2 4 8 2 3 7 )
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
– zip code
{place, state, province, community → }
– 4625-113
{Favões, Porto, Marco de Canaveses, Favões → }
– place
community →
– community
province →
– province
state →
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
C R E A T E S T A T I S T I C S s ( d e p e n d e n c i e s ) O N p l a c e _ n a m e , s t a t e _ n a m e , p r
i n c e _ n a m e F R O M z i p _ c
e s ; 2 3 4 A N A L Y Z E z i p _ c
e s ; S E L E C T s t x d e p e n d e n c i e s F R O M p g _ s t a t i s t i c _ e x t W H E R E s t x n a m e = ' s ' ; s t x d e p e n d e n c i e s
" 2 = > 3 " : . 7 8 9 4 6 7 , " 2 = > 4 " : . 7 7 4 3 3 3 , " 4 = > 2 " : . 9 3 3 , " 4 = > 3 " : . 9 9 3 1 6 7 , " 2 , 3 = > 4 " : . 9 5 1 6 6 7 , " 2 , 4 = > 3 " : . 9 9 8 3 3 3 , " 3 , 4 = > 2 " : . 9 3 3 }
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
p l a c e → s t a t e : . 7 8 9 = d P ( p l a c e = ' L i s b
' & s t a t e = ' L i s b
' ) = P ( p l a c e = ' L i s b
' ) * [ d + ( 1
) * P ( s t a t e = ' L i s b
' ) ] 2 6 9 4 1 * . 4 1 5 * ( . 7 8 9 + ( 1
7 8 9 ) * . 1 6 5 6 ) = 7 7 6 . 5
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T * F R O M z i p _ c
e s W H E R E p l a c e _ n a m e = ' L i s b
' A N D s t a t e _ n a m e = ' L i s b
' ; Q U E R Y P L A N
e q S c a n
z i p _ c
e s ( c
t = . . . 5 3 7 8 . 1 1 r
s = 7 7 6 w i d t h = 5 6 ) ( a c t u a l r
s = 9 1 6 5 l
s = 1 ) F i l t e r : ( ( ( p l a c e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) A N D ( ( s t a t e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) ) R
s R e m
e d b y F i l t e r : 1 9 7 7 7 6
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T * F R O M z i p _ c
e s W H E R E p l a c e _ n a m e = ' L i s b
' A N D s t a t e _ n a m e ! = ' L i s b
' ; Q U E R Y P L A N
e q S c a n
z i p _ c
e s ( c
t = . . . 5 3 7 8 . 1 1 r
s = 7 1 6 6 w i d t h = 5 6 ) ( a c t u a l r
s = 1 l
s = 1 ) F i l t e r : ( ( ( s t a t e _ n a m e ) : : t e x t < > ' L i s b
' : : t e x t ) A N D ( ( p l a c e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) ) R
s R e m
e d b y F i l t e r : 2 6 9 4 Functional dependencies only work with equalities.
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T * F R O M z i p _ c
e s W H E R E p l a c e _ n a m e = ' L i s b
' A N D s t a t e _ n a m e = ' P
t
; Q U E R Y P L A N
e q S c a n
z i p _ c
e s ( c
t = . . . 5 3 7 8 . 1 1 r
s = 1 3 7 4 w i d t h = 5 6 ) ( a c t u a l r
s = l
s = 1 ) F i l t e r : ( ( ( p l a c e _ n a m e ) : : t e x t = ' L i s b
' : : t e x t ) A N D ( ( s t a t e _ n a m e ) : : t e x t = ' P
t
: : t e x t ) ) R
s R e m
e d b y F i l t e r : 2 6 9 4 1 The queries need to respect the functional dependencies.
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T c
n t ( * ) F R O M z i p _ c
e s G R O U P B Y c
m u n i t y _ n a m e ; Q U E R Y P L A N
a s h A g g r e g a t e ( c
t = 3 4 4 1 2 6 . 9 2 . . 3 4 4 1 5 5 . 4 r
s = 2 8 6 w i d t h = 1 9 ) ( a c t u a l r
s = 3 8 4 5 l
s = 1 ) G r
p K e y : c
m u n i t y _ n a m e
S e q S c a n
z i p _ c
e s ( c
t = . . . 2 7 7 9 1 . 9 5 r
s = 1 3 2 4 4 9 9 5 w i d t h = 1 1 ) ( a c t u a l r
s = 1 3 2 4 4 2 2 4 l
s = 1 ) P l a n n i n g T i m e : . 2 1 9 m s E x e c u t i
T i m e : 6 6 6 4 . 7 5 2 m s
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 S E L E C T a t t n a m e , n _ d i s t i n c t F R O M p g _ s t a t s W H E R E t a b l e n a m e = ' z i p _ c
e s ' ; a t t n a m e | n _ d i s t i n c t
l a c e _ n a m e | 6 2 3 9 s t a t e _ n a m e | 2 l a t i t u d e | 5 5 3 2 l
g i t u d e | 5 1 3 5 p r
i n c e _ n a m e | 3 6 p
t a l _ c
e | 1 7 1 1 9 9 c
m u n i t y _ n a m e | 2 8 6 ( 7 r
s )
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T c
n t ( * ) F R O M z i p _ c
e s G R O U P B Y p r
i n c e _ n a m e , c
m u n i t y _ n a m e ; Q U E R Y P L A N
r
p A g g r e g a t e ( c
t = 2 3 8 7 9 7 . 9 2 . . 2 5 2 9 1 3 5 . 7 5 r
s = 8 7 5 1 6 r
s = 8 7 5 1 6 w i d t h = 2 9 ) ( a c t u a l r
s = 3 8 4 5 r
s = 3 8 4 5 l
s = 1 ) G r
p K e y : p r
i n c e _ n a m e , c
m u n i t y _ n a m e
S
t ( c
t = 2 3 8 7 9 7 . 9 2 . . 2 4 2 1 8 3 . 4 1 r
s = 1 3 2 4 4 9 9 5 w i d t h = 2 1 ) ( a c t u a l r
s = 1 3 2 4 4 2 2 4 l
s = 1 ) S
t K e y : p r
i n c e _ n a m e , c
m u n i t y _ n a m e S
t M e t h
: e x t e r n a l m e r g e D i s k : 4 1 5 6 2 4 k B
S e q S c a n
z i p _ c
e s ( c
t = . . . 2 7 7 9 1 . 9 5 r
s = 1 3 2 4 4 9 9 5 w i d t h = 2 1 ) ( a c t u a l r
s = 1 3 2 4 4 2 2 4 l
s = 1 ) P l a n n i n g T i m e : 1 . 1 1 6 m s E x e c u t i
T i m e : 4 8 5 9 1 . 3 2 6 m s
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T c
n t ( * ) F R O M z i p _ c
e s G R O U P B Y p r
i n c e _ n a m e , c
m u n i t y _ n a m e ; Q U E R Y P L A N
r
p A g g r e g a t e G r
p A g g r e g a t e ( c
t = 2 3 8 7 9 7 . 9 2 . . 2 5 2 9 1 3 5 . 7 5 r
s = 8 7 5 1 6 r
s = 8 7 5 1 6 w i d t h = 2 9 ) ( a c t u a l r
s = 3 8 4 5 r
s = 3 8 4 5 l
s = 1 ) G r
p K e y : p r
i n c e _ n a m e , c
m u n i t y _ n a m e
S
t S
t ( c
t = 2 3 8 7 9 7 . 9 2 . . 2 4 2 1 8 3 . 4 1 r
s = 1 3 2 4 4 9 9 5 w i d t h = 2 1 ) ( a c t u a l r
s = 1 3 2 4 4 2 2 4 l
s = 1 ) S
t K e y : p r
i n c e _ n a m e , c
m u n i t y _ n a m e S
t M e t h
: e x t e r n a l m e r g e D i s k : 4 1 5 6 2 4 k B
S e q S c a n
z i p _ c
e s ( c
t = . . . 2 7 7 9 1 . 9 5 r
s = 1 3 2 4 4 9 9 5 w i d t h = 2 1 ) ( a c t u a l r
s = 1 3 2 4 4 2 2 4 l
s = 1 ) P l a n n i n g T i m e : 1 . 1 1 6 m s E x e c u t i
T i m e : 4 8 5 9 1 . 3 2 6 m s
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
n d i s t i n c t ( p r
i n c e , c
m u n i t y ) = n d i s t i n c t ( p r
i n c e ) * n d i s t i n c t ( c
m u n i t y ) 3 6 * 2 8 6 = 8 7 5 1 6
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 C R E A T E S T A T I S T I C S s ( n d i s t i n c t ) O N s t a t e _ n a m e , p r
i n c e _ n a m e , c
m u n i t y _ n a m e F R O M z i p _ c
e s ; A N A L Y Z E z i p _ c
e s ; S E L E C T s t x n d i s t i n c t F R O M p g _ s t a t i s t i c _ e x t ; s t x n d i s t i n c t
" 3 , 4 " : 3 8 , " 3 , 5 " : 2 8 5 8 , " 4 , 5 " : 2 8 5 8 , " 3 , 4 , 5 " : 2 8 5 8 }
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018 E X P L A I N ( A N A L Y Z E , T I M I N G
f ) S E L E C T c
n t ( * ) F R O M z i p _ c
e s G R O U P B Y p r
i n c e _ n a m e , c
m u n i t y _ n a m e ; Q U E R Y P L A N
a s h A g g r e g a t e ( c
t = 1 2 5 6 9 . 2 6 . . 1 2 5 9 7 . 8 4 r
s = 2 8 5 8 w i d t h = 3 6 ) ( a c t u a l r
s = 3 8 4 5 l
s = 1 ) G r
p K e y : s t a t e _ n a m e , p r
i n c e _ n a m e , c
m u n i t y _ n a m e
S e q S c a n
z i p _ c
e s ( c
t = . . . 6 9 4 6 7 . 1 3 r
s = 3 3 1 2 1 3 w i d t h = 2 8 ) ( a c t u a l r
s = 3 3 1 1 5 6 l
s = 1 ) P l a n n i n g T i m e : 1 . 3 6 7 m s E x e c u t i
T i m e : 2 3 4 3 . 8 4 6 m s
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
– unreliable estimates with multiple columns – HashAggregate can’t spill to disk (OOM) – rather than crash do Sort+GroupAggregate (slow)
– make multi-column ndistinct estimates more reliable – reduced danger of OOM – large tables + GROUP BY multiple columns
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
– MCV lists, histograms, …
– currently only simple column references – alternative to functional indexes
– using MCV lists – special multi-table statistics (syntax already supports it)
https://github.com/tvondra/create-statistics-talk
https://www.2ndQuadrant.com
pgconf.eu 2018
Lisbon, October 23-26, 2018
Questions?
tomas.vondra@2ndquadrant.com tomas@pgaddict.com
@fuzzycz