Re: [HACKERS] Alternative to LIMIT in SELECT ?

Поиск
Список
Период
Сортировка
От Tatsuo Ishii
Тема Re: [HACKERS] Alternative to LIMIT in SELECT ?
Дата
Msg-id 199810140411.NAA21403@srapc451.sra.co.jp
обсуждение исходный текст
Ответ на Re: [HACKERS] Alternative to LIMIT in SELECT ?  (Tatsuo Ishii <t-ishii@sra.co.jp>)
Ответы Re: [HACKERS] Alternative to LIMIT in SELECT ?
Список 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@sra.co.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

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] Re: inet/cidr/bind
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] Alternative to LIMIT in SELECT ?