Skip to content

Commit 8cec4cf

Browse files
committed
New QUERY_LIMIT set command.
1 parent 39f2ec5 commit 8cec4cf

File tree

6 files changed

+161
-18
lines changed

6 files changed

+161
-18
lines changed

doc/src/sgml/ref/set.sgml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,44 @@ Equivalent to specifying <command>SET R_PLANS=Off</command>.
415415
The frontend may be initialized by setting the PGRPLANS
416416
environment variable.
417417

418+
<varlistentry>
419+
<term>
420+
QUERY_LIMIT
421+
</term>
422+
<listitem>
423+
<para>
424+
Sets the number of rows returned by a query.
425+
426+
<variablelist>
427+
<varlistentry>
428+
<term>
429+
Value
430+
</term>
431+
<listitem>
432+
<para>
433+
Maximum number of rows to return for a query. The default is unlimited.
434+
<varlistentry>
435+
<term>
436+
<replaceable class="parameter">#</replaceable>
437+
</term>
438+
<listitem>
439+
<para>
440+
Sets the maximum number of rows returned by a
441+
query to <replaceable class="parameter">#</replaceable>.
442+
<varlistentry>
443+
<term>
444+
DEFAULT
445+
</term>
446+
<listitem>
447+
<para>
448+
Sets the number of rows returned by a query to unlimited.
449+
</varlistentry>
450+
451+
<para>
452+
By default, there is no limit to the number of rows
453+
returned by a query.
454+
</variablelist>
455+
418456
</VARLISTENTRY>
419457
</VARIABLELIST>
420458
</REFSECT2>

src/backend/commands/variable.c

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Routines for handling of 'SET var TO',
33
* 'SHOW var' and 'RESET var' statements.
44
*
5-
* $Id: variable.c,v 1.15 1998/10/08 23:50:28 tgl Exp $
5+
* $Id: variable.c,v 1.16 1998/10/14 05:09:58 momjian Exp $
66
*
77
*/
88

@@ -18,6 +18,10 @@
1818
#ifdef MULTIBYTE
1919
#include "mb/pg_wchar.h"
2020
#endif
21+
#ifdef QUERY_LIMIT
22+
#include "executor/executor.h"
23+
#include "executor/execdefs.h"
24+
#endif
2125

2226
static bool show_date(void);
2327
static bool reset_date(void);
@@ -40,6 +44,11 @@ static bool parse_geqo(const char *);
4044
static bool show_ksqo(void);
4145
static bool reset_ksqo(void);
4246
static bool parse_ksqo(const char *);
47+
#ifdef QUERY_LIMIT
48+
static bool show_query_limit(void);
49+
static bool reset_query_limit(void);
50+
static bool parse_query_limit(const char *);
51+
#endif
4352

4453
extern Cost _cpu_page_wight_;
4554
extern Cost _cpu_index_page_wight_;
@@ -48,7 +57,11 @@ extern int32 _use_geqo_rels_;
4857
extern bool _use_right_sided_plans_;
4958
extern bool _use_keyset_query_optimizer;
5059

51-
/*-----------------------------------------------------------------------*/
60+
/*
61+
*
62+
* Get_Token
63+
*
64+
*/
5265
static const char *
5366
get_token(char **tok, char **val, const char *str)
5467
{
@@ -149,7 +162,11 @@ get_token(char **tok, char **val, const char *str)
149162
return str;
150163
}
151164

152-
/*-----------------------------------------------------------------------*/
165+
/*
166+
*
167+
* GEQO
168+
*
169+
*/
153170
static bool
154171
parse_geqo(const char *value)
155172
{
@@ -221,6 +238,11 @@ reset_geqo(void)
221238
return TRUE;
222239
}
223240

241+
/*
242+
*
243+
* R_PLANS
244+
*
245+
*/
224246
static bool
225247
parse_r_plans(const char *value)
226248
{
@@ -240,7 +262,6 @@ parse_r_plans(const char *value)
240262
return TRUE;
241263
}
242264

243-
/*-----------------------------------------------------------------------*/
244265
static bool
245266
show_r_plans()
246267
{
@@ -264,7 +285,11 @@ reset_r_plans()
264285
return TRUE;
265286
}
266287

267-
/*-----------------------------------------------------------------------*/
288+
/*
289+
*
290+
* COST_HEAP
291+
*
292+
*/
268293
static bool
269294
parse_cost_heap(const char *value)
270295
{
@@ -297,7 +322,11 @@ reset_cost_heap()
297322
return TRUE;
298323
}
299324

300-
/*-----------------------------------------------------------------------*/
325+
/*
326+
*
327+
* COST_INDEX
328+
*
329+
*/
301330
static bool
302331
parse_cost_index(const char *value)
303332
{
@@ -330,7 +359,11 @@ reset_cost_index()
330359
return TRUE;
331360
}
332361

333-
/*-----------------------------------------------------------------------*/
362+
/*
363+
*
364+
* DATE_STYLE
365+
*
366+
*/
334367
static bool
335368
parse_date(const char *value)
336369
{
@@ -448,6 +481,11 @@ static char *defaultTZ = NULL;
448481
static char TZvalue[64];
449482
static char tzbuf[64];
450483

484+
/*
485+
*
486+
* TIMEZONE
487+
*
488+
*/
451489
/* parse_timezone()
452490
* Handle SET TIME ZONE...
453491
* Try to save existing TZ environment variable for later use in RESET TIME ZONE.
@@ -545,7 +583,53 @@ reset_timezone()
545583
return TRUE;
546584
} /* reset_timezone() */
547585

586+
/*
587+
*
588+
* Query_limit
589+
*
590+
*/
591+
#ifdef QUERY_LIMIT
592+
static bool
593+
parse_query_limit(const char *value)
594+
{
595+
int32 limit;
596+
597+
if (value == NULL) {
598+
reset_query_limit();
599+
return(TRUE);
600+
}
601+
limit = pg_atoi(value, sizeof(int32), '\0');
602+
if (limit <= -1) {
603+
elog(ERROR, "Bad value for # of query limit (%s)", value);
604+
}
605+
ExecutorLimit(limit);
606+
return(TRUE);
607+
}
608+
609+
static bool
610+
show_query_limit(void)
611+
{
612+
int limit;
613+
614+
limit = ExecutorGetLimit();
615+
if (limit == ALL_TUPLES) {
616+
elog(NOTICE, "No query limit is set");
617+
} else {
618+
elog(NOTICE, "query limit is %d",limit);
619+
}
620+
return(TRUE);
621+
}
622+
623+
static bool
624+
reset_query_limit(void)
625+
{
626+
ExecutorLimit(ALL_TUPLES);
627+
return(TRUE);
628+
}
629+
#endif
630+
548631
/*-----------------------------------------------------------------------*/
632+
549633
struct VariableParsers
550634
{
551635
const char *name;
@@ -584,6 +668,11 @@ struct VariableParsers
584668
{
585669
"ksqo", parse_ksqo, show_ksqo, reset_ksqo
586670
},
671+
#ifdef QUERY_LIMIT
672+
{
673+
"query_limit", parse_query_limit, show_query_limit, reset_query_limit
674+
},
675+
#endif
587676
{
588677
NULL, NULL, NULL, NULL
589678
}

src/backend/executor/execMain.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.57 1998/10/01 02:03:58 tgl Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.58 1998/10/14 05:10:00 momjian Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -83,14 +83,18 @@ static int queryLimit = ALL_TUPLES;
8383
#undef ALL_TUPLES
8484
#define ALL_TUPLES queryLimit
8585

86-
int ExecutorLimit(int limit);
87-
8886
int
8987
ExecutorLimit(int limit)
9088
{
9189
return queryLimit = limit;
9290
}
9391

92+
int
93+
ExecutorGetLimit()
94+
{
95+
return queryLimit;
96+
}
97+
9498
#endif
9599

96100
/* ----------------------------------------------------------------

src/bin/psql/psqlHelp.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Id: psqlHelp.h,v 1.53 1998/10/08 01:10:28 tgl Exp $
8+
* $Id: psqlHelp.h,v 1.54 1998/10/14 05:10:02 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -296,10 +296,10 @@ static struct _helpStruct QL_HELP[] = {
296296
"set run-time environment back to default",
297297
#ifdef MULTIBYTE
298298
"\
299-
\tRESET DateStyle|GEQO|R_PLANS|CLIENT_ENCODING"},
299+
\tRESET DateStyle|GEQO|R_PLANS|QUERY_LIMIT|CLIENT_ENCODING"},
300300
#else
301301
"\
302-
\tRESET DateStyle|GEQO|R_PLANS"},
302+
\tRESET DateStyle|GEQO|R_PLANS|QUERY_LIMIT"},
303303
#endif
304304
{"revoke",
305305
"revoke access control from a user or group",
@@ -329,21 +329,23 @@ static struct _helpStruct QL_HELP[] = {
329329
\tSET DateStyle TO 'ISO'|'SQL'|'Postgres'|'European'|'US'|'NonEuropean'\n\
330330
set GEQO TO 'ON[=#]'|'OFF'\n\
331331
set R_PLANS TO 'ON'|'OFF'\n\
332+
set QUERY_LIMIT TO #\n\
332333
set CLIENT_ENCODING TO 'EUC_JP'|'SJIS'|'EUC_CN'|'EUC_KR'|'EUC_TW'|'MULE_INTERNAL'|'LATIN1'|'LATIN2'|'LATIN3'|'LATIN4'|'LATIN5'"},
333334
#else
334335
"\
335336
\tSET DateStyle TO 'ISO'|'SQL'|'Postgres'|'European'|'US'|'NonEuropean'\n\
336337
set GEQO TO 'ON[=#]'|'OFF'\n\
337-
set R_PLANS TO 'ON'| 'OFF'"},
338+
set R_PLANS TO 'ON'| 'OFF'\n\
339+
set QUERY_LIMIT TO #"},
338340
#endif
339341
{"show",
340342
"show current run-time environment",
341343
#ifdef MULTIBYTE
342344
"\
343-
\tSHOW DateStyle|GEQO|R_PLANS|CLIENT_ENCODING"},
345+
\tSHOW DateStyle|GEQO|R_PLANS|QUERY_LIMIT|CLIENT_ENCODING"},
344346
#else
345347
"\
346-
\tSHOW DateStyle|GEQO|R_PLANS"},
348+
\tSHOW DateStyle|GEQO|R_PLANS|QUERY_LIMIT"},
347349
#endif
348350
{"unlisten",
349351
"stop listening for notification on a condition name",

src/include/executor/executor.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: executor.h,v 1.26 1998/10/08 18:30:29 momjian Exp $
9+
* $Id: executor.h,v 1.27 1998/10/14 05:10:05 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -86,6 +86,10 @@ extern TupleDesc ExecutorStart(QueryDesc *queryDesc, EState *estate);
8686
extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count);
8787
extern void ExecutorEnd(QueryDesc *queryDesc, EState *estate);
8888
extern HeapTuple ExecConstraints(char *caller, Relation rel, HeapTuple tuple);
89+
#ifdef QUERY_LIMIT
90+
extern int ExecutorLimit(int limit);
91+
extern int ExecutorGetLimit(void);
92+
#endif
8993

9094
/*
9195
* prototypes from functions in execProcnode.c

src/man/set.l

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" This is -*-nroff-*-
22
.\" XXX standard disclaimer belongs here....
3-
.\" $Header: /cvsroot/pgsql/src/man/Attic/set.l,v 1.10 1998/10/14 02:36:44 momjian Exp $
3+
.\" $Header: /cvsroot/pgsql/src/man/Attic/set.l,v 1.11 1998/10/14 05:10:12 momjian Exp $
44
.TH SET SQL 05/14/97 PostgreSQL PostgreSQL
55
.SH NAME
66
set - set run-time parameters for session
@@ -76,6 +76,12 @@ by default. It's not used by GEQO anyway.
7676
off - do not use right-hand plan evaluation
7777
.fi
7878

79+
.PP
80+
.IR QUERY_LIMIT
81+
restricts the number of rows returned by a query.
82+
The default is unlimited.
83+
84+
7985
.SH EXAMPLES
8086
.nf
8187
--

0 commit comments

Comments
 (0)