1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Allow the planner's estimate of the fraction of a cursor's rows that will be

retrieved to be controlled through a GUC variable.

Robert Hell
This commit is contained in:
Tom Lane
2008-05-02 21:26:10 +00:00
parent cf9f6c8d8e
commit db147b3483
5 changed files with 58 additions and 8 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.232 2008/04/17 21:22:14 tgl Exp $
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.233 2008/05/02 21:26:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -42,6 +42,9 @@
#include "utils/syscache.h"
/* GUC parameter */
double cursor_tuple_fraction = DEFAULT_CURSOR_TUPLE_FRACTION;
/* Hook for plugins to get control in planner() */
planner_hook_type planner_hook = NULL;
@ -142,11 +145,23 @@ standard_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
{
/*
* We have no real idea how many tuples the user will ultimately FETCH
* from a cursor, but it seems a good bet that he doesn't want 'em
* all. Optimize for 10% retrieval (you gotta better number? Should
* this be a SETtable parameter?)
* from a cursor, but it is often the case that he doesn't want 'em
* all, or would prefer a fast-start plan anyway so that he can
* process some of the tuples sooner. Use a GUC parameter to decide
* what fraction to optimize for.
*/
tuple_fraction = 0.10;
tuple_fraction = cursor_tuple_fraction;
/*
* We document cursor_tuple_fraction as simply being a fraction,
* which means the edge cases 0 and 1 have to be treated specially
* here. We convert 1 to 0 ("all the tuples") and 0 to a very small
* fraction.
*/
if (tuple_fraction >= 1.0)
tuple_fraction = 0.0;
else if (tuple_fraction <= 0.0)
tuple_fraction = 1e-10;
}
else
{