Re: [HACKERS] Stats for multi-column indexes

2007-03-21 Thread Csaba Nagy
This should read: > Considering that the FK part is unique, the ^^PK^^ > skewness in the relationship is completely determined by the FK part's > histogram. That would give at least a lower/upper bound and MCVs to the > relationship. Cheers, Csaba.

Re: [HACKERS] Stats for multi-column indexes

2007-03-21 Thread Csaba Nagy
On Tue, 2007-03-20 at 18:12, Josh Berkus wrote: > Tom, > > > Actually, I think you don't particularly need stats for that in most > > cases --- if the planner simply took note that the FK relationship > > exists, it would know that each row of the FK side joins to exactly > > one row of the PK sid

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Tom Lane
"Jim C. Nasby" <[EMAIL PROTECTED]> writes: > It might be worth coming up with a different means to store the > histogram for the multi-column case. A separate array for each column involved seems a whole lot less fragile than pretending we can handle mixed-type arrays. We probably need a differen

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Jim C. Nasby
On Mon, Mar 19, 2007 at 06:55:56PM -0700, Jeff Davis wrote: > On Mon, 2007-03-19 at 21:24 -0400, Tom Lane wrote: > > Jeff Davis <[EMAIL PROTECTED]> writes: > > > We can already keep stats for a functional index. Is there a reason we > > > can't keep stats for a multi-column index? > > > > The ques

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Tom Lane
Josh Berkus writes: >> Actually, I think you don't particularly need stats for that in most >> cases --- if the planner simply took note that the FK relationship >> exists, it would know that each row of the FK side joins to exactly >> one row of the PK side, which in typical cases is sufficient.

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Jeff Davis
On Tue, 2007-03-20 at 18:12 +0100, Josh Berkus wrote: > Tom, > > > Actually, I think you don't particularly need stats for that in most > > cases --- if the planner simply took note that the FK relationship > > exists, it would know that each row of the FK side joins to exactly > > one row of the

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Jeff Davis
On Tue, 2007-03-20 at 09:03 +, Simon Riggs wrote: > We should allow the DBA to specify which groups of cols to keep > statistics on, if there is no index on that group. > > That solves the combinatorial explosion problem. > I think it would be a good first step if we could just keep stats on

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Josh Berkus
Tom, Actually, I think you don't particularly need stats for that in most cases --- if the planner simply took note that the FK relationship exists, it would know that each row of the FK side joins to exactly one row of the PK side, which in typical cases is sufficient. Is it? What about the

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Tom Lane
Alvaro Herrera <[EMAIL PROTECTED]> writes: > It was also suggested that column pairs in FK relationship could be > automatically enabled. So you don't need to specify those manually. Actually, I think you don't particularly need stats for that in most cases --- if the planner simply took note tha

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Peter Eisentraut
Alvaro Herrera wrote: > Now, the hard question is deciding what to keep track of. I don't > think MCV makes much sense, because what's the MCV of two columns? The combination that occurs most often. -- Peter Eisentraut http://developer.postgresql.org/~petere/ ---(end o

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Alvaro Herrera
Richard Huxton wrote: > Simon Riggs wrote: > >On Tue, 2007-03-20 at 14:14 +1200, Mark Kirkwood wrote: > >>Jeff Davis wrote: > >>>I know we can't keep stats on every combination of columns. My initial > >>>idea would be to only keep stats about a multi-column index (and > >>>probably optional for th

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Richard Huxton
Simon Riggs wrote: On Tue, 2007-03-20 at 14:14 +1200, Mark Kirkwood wrote: Jeff Davis wrote: I know we can't keep stats on every combination of columns. My initial idea would be to only keep stats about a multi-column index (and probably optional for those, too). Maybe you would want to keep s

Re: [HACKERS] Stats for multi-column indexes

2007-03-20 Thread Simon Riggs
On Tue, 2007-03-20 at 14:14 +1200, Mark Kirkwood wrote: > Jeff Davis wrote: > > > > I know we can't keep stats on every combination of columns. My initial > > idea would be to only keep stats about a multi-column index (and > > probably optional for those, too). > > > > Maybe you would want to ke

Re: [HACKERS] Stats for multi-column indexes

2007-03-19 Thread Mark Kirkwood
Jeff Davis wrote: I know we can't keep stats on every combination of columns. My initial idea would be to only keep stats about a multi-column index (and probably optional for those, too). Maybe you would want to keep single column indexes too, so that (more) accurate estimates for bitmap-an

Re: [HACKERS] Stats for multi-column indexes

2007-03-19 Thread Jeff Davis
On Mon, 2007-03-19 at 21:24 -0400, Tom Lane wrote: > Jeff Davis <[EMAIL PROTECTED]> writes: > > We can already keep stats for a functional index. Is there a reason we > > can't keep stats for a multi-column index? > > The questions that need to be answered are (1) what stats are you gonna > collec

Re: [HACKERS] Stats for multi-column indexes

2007-03-19 Thread Tom Lane
Jeff Davis <[EMAIL PROTECTED]> writes: > We can already keep stats for a functional index. Is there a reason we > can't keep stats for a multi-column index? The questions that need to be answered are (1) what stats are you gonna collect, and (2) exactly what are you going to do with them when you

[HACKERS] Stats for multi-column indexes

2007-03-19 Thread Jeff Davis
I know the idea has come up a few times to do cross-column statistics to improve plans when the data distributions are dependent. I found a couple references in the archives: http://archives.postgresql.org/pgsql-hackers/2006-09/msg02118.php http://archives.postgresql.org/pgsql-hackers/2006-08/msg0