Optimize join selectivity estimation by not reading MCV stats for unique join attributes - Mailing list pgsql-hackers

From David Geier
Subject Optimize join selectivity estimation by not reading MCV stats for unique join attributes
Date
Msg-id b9846ca0-5f1c-9b26-5881-aad3f42b07f0@gmail.com
Whole thread Raw
Responses Re: Optimize join selectivity estimation by not reading MCV stats for unique join attributes
List pgsql-hackers
Hi hackers,

eqjoinsel() can be optimized by not reading MCV stats if at least one of 
the two join attributes is unique. As primary keys are implicitly unique 
this situation can occur frequently. For unique columns no MCV stats are 
stored and eqjoinsel_inner() and eqjoinsel_semi(), called from 
eqjoinsel(), only consider MCV stats in the join selectivity computation 
if they're present on both columns. Attached is a small patch that 
implements the skipping.

With this change we saw some queries improve planning time by more than 
2x, especially with larger values for default_statistics_target. That's 
because get_attstatsslot() deconstructs the array holding the MCV. The 
size of that array depends on default_statistics_target.

Thanks for your consideration!

--
David Geier
(ServiceNow)

Attachment

pgsql-hackers by date:

Previous
From: Pavel Borisov
Date:
Subject: Re: Lockless queue of waiters in LWLock
Next
From: Maxim Orlov
Date:
Subject: Re: Add LSN along with offset to error messages reported for WAL file read/write/validate header failures