diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-01-22 20:16:42 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-01-22 20:16:42 +0000 |
| commit | c4d0ff32e9bfc5f9876854c093486e2a9428a617 (patch) | |
| tree | 0241460b46d84846f5cc80e3cf9eeaae1a84cd1c /src/backend/optimizer | |
| parent | c7b4047234f3b42ab7af964d63593de15dca5288 (diff) | |
| download | postgresql-c4d0ff32e9bfc5f9876854c093486e2a9428a617.tar.gz | |
Make estimation of mergejoin scan selectivities more robust, per recent
example from RaÇl GutiÅrrez.
Diffstat (limited to 'src/backend/optimizer')
| -rw-r--r-- | src/backend/optimizer/path/costsize.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 5146517132..d0df5cab11 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -42,7 +42,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.101 2003/01/20 18:54:49 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.102 2003/01/22 20:16:40 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -791,8 +791,22 @@ cost_mergejoin(Path *path, Query *root, innerscansel = firstclause->left_mergescansel; } + /* convert selectivity to row count; must scan at least one row */ + outer_rows = ceil(outer_path->parent->rows * outerscansel); + if (outer_rows < 1) + outer_rows = 1; inner_rows = ceil(inner_path->parent->rows * innerscansel); + if (inner_rows < 1) + inner_rows = 1; + + /* + * Readjust scan selectivities to account for above rounding. This is + * normally an insignificant effect, but when there are only a few rows + * in the inputs, failing to do this makes for a large percentage error. + */ + outerscansel = outer_rows / outer_path->parent->rows; + innerscansel = inner_rows / inner_path->parent->rows; /* cost of source data */ |
