mirror of
https://github.com/postgres/postgres.git
synced 2025-11-13 16:22:44 +03:00
Make estimation of mergejoin scan selectivities more robust, per recent
example from RaÇl GutiÅrrez.
This commit is contained in:
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user