Re: [HACKERS] Alternative to LIMIT in SELECT ?

From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
To: t-ishii(at)sra(dot)co(dot)jp
Cc: "Thomas G(dot) Lockhart" <lockhart(at)alumni(dot)caltech(dot)edu>, Marc Howard Zuckman <marc(at)fallon(dot)classyad(dot)com>, Eric Lee Green <eric(at)linux-hw(dot)com>, "Marc G(dot) Fournier" <scrappy(at)hub(dot)org>, Jeff Hoffmann <jeff(at)remapcorp(dot)com>, PostgreSQL-development <hackers(at)postgreSQL(dot)org>
Subject: Re: [HACKERS] Alternative to LIMIT in SELECT ?
Date: 1998-10-14 04:11:20
Message-ID: 199810140411.NAA21403@srapc451.sra.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>>> I've found ExecutorLimit() (in executor/execMain.c) is useful for me
>>> especially when issuing an ad-hock query via psql. I personally use
>>> the function with customized set command.
>>
>>Looks interesting. So where are the patches? :)
>
>I'll post pacthes within 24 hours:-)

Here it is.
--
Tatsuo Ishii
t-ishii(at)sra(dot)co(dot)jp
----------------------------------------------------------------
*** backend/commands/variable.c.orig Fri Oct 9 09:56:51 1998
--- backend/commands/variable.c Wed Oct 14 13:06:15 1998
***************
*** 18,23 ****
--- 18,27 ----
#ifdef MULTIBYTE
#include "mb/pg_wchar.h"
#endif
+ #ifdef QUERY_LIMIT
+ #include "executor/executor.h"
+ #include "executor/execdefs.h"
+ #endif

static bool show_date(void);
static bool reset_date(void);
***************
*** 40,45 ****
--- 44,54 ----
static bool show_ksqo(void);
static bool reset_ksqo(void);
static bool parse_ksqo(const char *);
+ #ifdef QUERY_LIMIT
+ static bool show_query_limit(void);
+ static bool reset_query_limit(void);
+ static bool parse_query_limit(const char *);
+ #endif

extern Cost _cpu_page_wight_;
extern Cost _cpu_index_page_wight_;
***************
*** 546,551 ****
--- 555,600 ----
} /* reset_timezone() */

/*-----------------------------------------------------------------------*/
+ #ifdef QUERY_LIMIT
+ static bool
+ parse_query_limit(const char *value)
+ {
+ int32 limit;
+
+ if (value == NULL) {
+ reset_query_limit();
+ return(TRUE);
+ }
+ limit = pg_atoi(value, sizeof(int32), '\0');
+ if (limit <= -1) {
+ elog(ERROR, "Bad value for # of query limit (%s)", value);
+ }
+ ExecutorLimit(limit);
+ return(TRUE);
+ }
+
+ static bool
+ show_query_limit(void)
+ {
+ int limit;
+
+ limit = ExecutorGetLimit();
+ if (limit == ALL_TUPLES) {
+ elog(NOTICE, "No query limit is set");
+ } else {
+ elog(NOTICE, "query limit is %d",limit);
+ }
+ return(TRUE);
+ }
+
+ static bool
+ reset_query_limit(void)
+ {
+ ExecutorLimit(ALL_TUPLES);
+ return(TRUE);
+ }
+ #endif
+ /*-----------------------------------------------------------------------*/
struct VariableParsers
{
const char *name;
***************
*** 584,589 ****
--- 633,643 ----
{
"ksqo", parse_ksqo, show_ksqo, reset_ksqo
},
+ #ifdef QUERY_LIMIT
+ {
+ "query_limit", parse_query_limit, show_query_limit, reset_query_limit
+ },
+ #endif
{
NULL, NULL, NULL, NULL
}
*** backend/executor/execMain.c.orig Thu Oct 1 11:03:58 1998
--- backend/executor/execMain.c Wed Oct 14 11:24:06 1998
***************
*** 83,94 ****
#undef ALL_TUPLES
#define ALL_TUPLES queryLimit

- int ExecutorLimit(int limit);
-
int
ExecutorLimit(int limit)
{
return queryLimit = limit;
}

#endif
--- 83,98 ----
#undef ALL_TUPLES
#define ALL_TUPLES queryLimit

int
ExecutorLimit(int limit)
{
return queryLimit = limit;
+ }
+
+ int
+ ExecutorGetLimit()
+ {
+ return queryLimit;
}

#endif
*** include/executor/executor.h.orig Fri Oct 9 10:02:07 1998
--- include/executor/executor.h Wed Oct 14 11:24:07 1998
***************
*** 86,91 ****
--- 86,95 ----
extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count);
extern void ExecutorEnd(QueryDesc *queryDesc, EState *estate);
extern HeapTuple ExecConstraints(char *caller, Relation rel, HeapTuple tuple);
+ #ifdef QUERY_LIMIT
+ extern int ExecutorLimit(int limit);
+ extern int ExecutorGetLimit(void);
+ #endif

/*
* prototypes from functions in execProcnode.c

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1998-10-14 05:12:52 Re: [HACKERS] Alternative to LIMIT in SELECT ?
Previous Message Bruce Momjian 1998-10-14 03:21:44 Re: [HACKERS] Re: inet/cidr/bind