mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Teach tuplesort.c about "top N" sorting, in which only the first N tuples
need be returned. We keep a heap of the current best N tuples and sift-up new tuples into it as we scan the input. For M input tuples this means only about M*log(N) comparisons instead of M*log(M), not to mention a lot less workspace when N is small --- avoiding spill-to-disk for large M is actually the most attractive thing about it. Patch includes planner and executor support for invoking this facility in ORDER BY ... LIMIT queries. Greg Stark, with some editorialization by moi.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.389 2007/04/26 16:13:12 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.390 2007/05/04 01:13:44 tgl Exp $
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
*/
|
||||
@@ -108,6 +108,9 @@ extern bool fullPageWrites;
|
||||
#ifdef TRACE_SORT
|
||||
extern bool trace_sort;
|
||||
#endif
|
||||
#ifdef DEBUG_BOUNDED_SORT
|
||||
extern bool optimize_bounded_sort;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SSL
|
||||
extern char *SSLCipherSuites;
|
||||
@@ -966,6 +969,20 @@ static struct config_bool ConfigureNamesBool[] =
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_BOUNDED_SORT
|
||||
/* this is undocumented because not exposed in a standard build */
|
||||
{
|
||||
{
|
||||
"optimize_bounded_sort", PGC_USERSET, QUERY_TUNING_METHOD,
|
||||
gettext_noop("Enable bounded sorting using heap sort."),
|
||||
NULL,
|
||||
GUC_NOT_IN_SAMPLE
|
||||
},
|
||||
&optimize_bounded_sort,
|
||||
true, NULL, NULL
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef WAL_DEBUG
|
||||
{
|
||||
{"wal_debug", PGC_SUSET, DEVELOPER_OPTIONS,
|
||||
@@ -1711,7 +1728,7 @@ static struct config_int ConfigureNamesInt[] =
|
||||
&server_version_num,
|
||||
PG_VERSION_NUM, PG_VERSION_NUM, PG_VERSION_NUM, NULL, NULL
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
{"log_temp_files", PGC_USERSET, LOGGING_WHAT,
|
||||
gettext_noop("Log the use of temporary files larger than this number of kilobytes."),
|
||||
@@ -2883,7 +2900,7 @@ InitializeGUCOptions(void)
|
||||
PGC_S_DEFAULT))
|
||||
elog(FATAL, "failed to initialize %s to %d",
|
||||
conf->gen.name, conf->boot_val);
|
||||
*conf->variable = conf->reset_val = conf->boot_val;
|
||||
*conf->variable = conf->reset_val = conf->boot_val;
|
||||
break;
|
||||
}
|
||||
case PGC_REAL:
|
||||
@@ -2897,7 +2914,7 @@ InitializeGUCOptions(void)
|
||||
PGC_S_DEFAULT))
|
||||
elog(FATAL, "failed to initialize %s to %g",
|
||||
conf->gen.name, conf->boot_val);
|
||||
*conf->variable = conf->reset_val = conf->boot_val;
|
||||
*conf->variable = conf->reset_val = conf->boot_val;
|
||||
break;
|
||||
}
|
||||
case PGC_STRING:
|
||||
|
Reference in New Issue
Block a user