Patch for - Change FETCH/MOVE to use int8 - Mailing list pgsql-patches

From Dhanaraj M
Subject Patch for - Change FETCH/MOVE to use int8
Date
Msg-id 44DEF61A.5070208@sun.com
Whole thread Raw
Responses Re: Patch for - Change FETCH/MOVE to use int8  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-patches
This patch is for the following TODO item.

SQL command:
-/Change LIMIT/OFFSET and FETCH/MOVE to use int8

/Since the limit/offset patch is already applied,
this patch is meant for Fetch/Move query.
I have tested the patch and it works for int64 values.
Please verify this.

Thanks
Dhanaraj
/
/

*** ./src/backend/commands/portalcmds.c.orig    Sat Aug 12 23:04:54 2006
--- ./src/backend/commands/portalcmds.c    Sat Aug 12 23:04:53 2006
***************
*** 176,183 ****
                     char *completionTag)
  {
      Portal        portal;
!     long        nprocessed;

      /*
       * Disallow empty-string cursor name (conflicts with protocol-level
       * unnamed portal).
--- 176,183 ----
                     char *completionTag)
  {
      Portal        portal;
!     int64        nprocessed;

      /*
       * Disallow empty-string cursor name (conflicts with protocol-level
       * unnamed portal).
***************
*** 209,215 ****

      /* Return command status if wanted */
      if (completionTag)
!         snprintf(completionTag, COMPLETION_TAG_BUFSIZE, "%s %ld",
                   stmt->ismove ? "MOVE" : "FETCH",
                   nprocessed);
  }
--- 209,215 ----

      /* Return command status if wanted */
      if (completionTag)
!         snprintf(completionTag, COMPLETION_TAG_BUFSIZE, "%s %lld",
                   stmt->ismove ? "MOVE" : "FETCH",
                   nprocessed);
  }
*** ./src/backend/parser/gram.y.orig    Sat Aug 12 23:04:57 2006
--- ./src/backend/parser/gram.y    Sun Aug 13 00:06:28 2006
***************
*** 116,122 ****

  %union
  {
!     int                    ival;
      char                chr;
      char                *str;
      const char            *keyword;
--- 116,122 ----

  %union
  {
!     int64                ival;
      char                chr;
      char                *str;
      const char            *keyword;
***************
*** 1180,1192 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision must not be negative",
!                                         $3)));
                      if ($3 > MAX_INTERVAL_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
!                                         $3, MAX_INTERVAL_PRECISION)));
                          $3 = MAX_INTERVAL_PRECISION;
                      }

--- 1180,1192 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision must not be negative",
!                                         (int)$3)));
                      if ($3 > MAX_INTERVAL_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
!                                         (int)$3, MAX_INTERVAL_PRECISION)));
                          $3 = MAX_INTERVAL_PRECISION;
                      }

***************
*** 2620,2626 ****
              ICONST
                  {
                      char buf[64];
!                     snprintf(buf, sizeof(buf), "%d", $1);
                      $$ = makeString(pstrdup(buf));
                  }
              | FCONST                                { $$ = makeString($1); }
--- 2620,2626 ----
              ICONST
                  {
                      char buf[64];
!                     snprintf(buf, sizeof(buf), "%d", (int)$1);
                      $$ = makeString(pstrdup(buf));
                  }
              | FCONST                                { $$ = makeString($1); }
***************
*** 6281,6293 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision must not be negative",
!                                         $3)));
                      if ($3 > MAX_INTERVAL_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
!                                         $3, MAX_INTERVAL_PRECISION)));
                          $3 = MAX_INTERVAL_PRECISION;
                      }
                      $$->typmod = INTERVAL_TYPMOD($3, $5);
--- 6281,6293 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision must not be negative",
!                                         (int)$3)));
                      if ($3 > MAX_INTERVAL_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
!                                         (int)$3, MAX_INTERVAL_PRECISION)));
                          $3 = MAX_INTERVAL_PRECISION;
                      }
                      $$->typmod = INTERVAL_TYPMOD($3, $5);
***************
*** 6408,6419 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("NUMERIC precision %d must be between 1 and %d",
!                                         $2, NUMERIC_MAX_PRECISION)));
                      if ($4 < 0 || $4 > $2)
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("NUMERIC scale %d must be between 0 and precision %d",
!                                         $4, $2)));

                      $$ = (($2 << 16) | $4) + VARHDRSZ;
                  }
--- 6408,6419 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("NUMERIC precision %d must be between 1 and %d",
!                                         (int)$2, NUMERIC_MAX_PRECISION)));
                      if ($4 < 0 || $4 > $2)
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("NUMERIC scale %d must be between 0 and precision %d",
!                                         (int)$4, (int)$2)));

                      $$ = (($2 << 16) | $4) + VARHDRSZ;
                  }
***************
*** 6423,6429 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("NUMERIC precision %d must be between 1 and %d",
!                                         $2, NUMERIC_MAX_PRECISION)));

                      $$ = ($2 << 16) + VARHDRSZ;
                  }
--- 6423,6429 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("NUMERIC precision %d must be between 1 and %d",
!                                         (int)$2, NUMERIC_MAX_PRECISION)));

                      $$ = ($2 << 16) + VARHDRSZ;
                  }
***************
*** 6441,6452 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("DECIMAL precision %d must be between 1 and %d",
!                                         $2, NUMERIC_MAX_PRECISION)));
                      if ($4 < 0 || $4 > $2)
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("DECIMAL scale %d must be between 0 and precision %d",
!                                         $4, $2)));

                      $$ = (($2 << 16) | $4) + VARHDRSZ;
                  }
--- 6441,6452 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("DECIMAL precision %d must be between 1 and %d",
!                                         (int)$2, NUMERIC_MAX_PRECISION)));
                      if ($4 < 0 || $4 > $2)
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("DECIMAL scale %d must be between 0 and precision %d",
!                                         (int)$4, (int)$2)));

                      $$ = (($2 << 16) | $4) + VARHDRSZ;
                  }
***************
*** 6456,6462 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("DECIMAL precision %d must be between 1 and %d",
!                                         $2, NUMERIC_MAX_PRECISION)));

                      $$ = ($2 << 16) + VARHDRSZ;
                  }
--- 6456,6462 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("DECIMAL precision %d must be between 1 and %d",
!                                         (int)$2, NUMERIC_MAX_PRECISION)));

                      $$ = ($2 << 16) + VARHDRSZ;
                  }
***************
*** 6662,6674 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("TIMESTAMP(%d)%s precision must not be negative",
!                                         $3, ($5 ? " WITH TIME ZONE": ""))));
                      if ($3 > MAX_TIMESTAMP_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("TIMESTAMP(%d)%s precision reduced to maximum allowed, %d",
!                                         $3, ($5 ? " WITH TIME ZONE": ""),
                                          MAX_TIMESTAMP_PRECISION)));
                          $3 = MAX_TIMESTAMP_PRECISION;
                      }
--- 6662,6674 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("TIMESTAMP(%d)%s precision must not be negative",
!                                         (int)$3, ($5 ? " WITH TIME ZONE": ""))));
                      if ($3 > MAX_TIMESTAMP_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("TIMESTAMP(%d)%s precision reduced to maximum allowed, %d",
!                                         (int)$3, ($5 ? " WITH TIME ZONE": ""),
                                          MAX_TIMESTAMP_PRECISION)));
                          $3 = MAX_TIMESTAMP_PRECISION;
                      }
***************
*** 6695,6707 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("TIME(%d)%s precision must not be negative",
!                                         $3, ($5 ? " WITH TIME ZONE": ""))));
                      if ($3 > MAX_TIME_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
!                                         $3, ($5 ? " WITH TIME ZONE": ""),
                                          MAX_TIME_PRECISION)));
                          $3 = MAX_TIME_PRECISION;
                      }
--- 6695,6707 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("TIME(%d)%s precision must not be negative",
!                                         (int)$3, ($5 ? " WITH TIME ZONE": ""))));
                      if ($3 > MAX_TIME_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("TIME(%d)%s precision reduced to maximum allowed, %d",
!                                         (int)$3, ($5 ? " WITH TIME ZONE": ""),
                                          MAX_TIME_PRECISION)));
                          $3 = MAX_TIME_PRECISION;
                      }
***************
*** 7435,7447 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("CURRENT_TIME(%d) precision must not be negative",
!                                         $3)));
                      if ($3 > MAX_TIME_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("CURRENT_TIME(%d) precision reduced to maximum allowed, %d",
!                                         $3, MAX_TIME_PRECISION)));
                          $3 = MAX_TIME_PRECISION;
                      }
                      d->typmod = $3;
--- 7435,7447 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("CURRENT_TIME(%d) precision must not be negative",
!                                         (int)$3)));
                      if ($3 > MAX_TIME_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("CURRENT_TIME(%d) precision reduced to maximum allowed, %d",
!                                         (int)$3, MAX_TIME_PRECISION)));
                          $3 = MAX_TIME_PRECISION;
                      }
                      d->typmod = $3;
***************
*** 7480,7492 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("CURRENT_TIMESTAMP(%d) precision must not be negative",
!                                         $3)));
                      if ($3 > MAX_TIMESTAMP_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("CURRENT_TIMESTAMP(%d) precision reduced to maximum allowed, %d",
!                                         $3, MAX_TIMESTAMP_PRECISION)));
                          $3 = MAX_TIMESTAMP_PRECISION;
                      }
                      d->typmod = $3;
--- 7480,7492 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("CURRENT_TIMESTAMP(%d) precision must not be negative",
!                                         (int)$3)));
                      if ($3 > MAX_TIMESTAMP_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("CURRENT_TIMESTAMP(%d) precision reduced to maximum allowed, %d",
!                                         (int)$3, MAX_TIMESTAMP_PRECISION)));
                          $3 = MAX_TIMESTAMP_PRECISION;
                      }
                      d->typmod = $3;
***************
*** 7527,7539 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("LOCALTIME(%d) precision must not be negative",
!                                         $3)));
                      if ($3 > MAX_TIME_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("LOCALTIME(%d) precision reduced to maximum allowed, %d",
!                                         $3, MAX_TIME_PRECISION)));
                          $3 = MAX_TIME_PRECISION;
                      }
                      d->typmod = $3;
--- 7527,7539 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("LOCALTIME(%d) precision must not be negative",
!                                         (int)$3)));
                      if ($3 > MAX_TIME_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("LOCALTIME(%d) precision reduced to maximum allowed, %d",
!                                         (int)$3, MAX_TIME_PRECISION)));
                          $3 = MAX_TIME_PRECISION;
                      }
                      d->typmod = $3;
***************
*** 7575,7587 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("LOCALTIMESTAMP(%d) precision must not be negative",
!                                         $3)));
                      if ($3 > MAX_TIMESTAMP_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("LOCALTIMESTAMP(%d) precision reduced to maximum allowed, %d",
!                                         $3, MAX_TIMESTAMP_PRECISION)));
                          $3 = MAX_TIMESTAMP_PRECISION;
                      }
                      d->typmod = $3;
--- 7575,7587 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("LOCALTIMESTAMP(%d) precision must not be negative",
!                                         (int)$3)));
                      if ($3 > MAX_TIMESTAMP_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("LOCALTIMESTAMP(%d) precision reduced to maximum allowed, %d",
!                                         (int)$3, MAX_TIMESTAMP_PRECISION)));
                          $3 = MAX_TIMESTAMP_PRECISION;
                      }
                      d->typmod = $3;
***************
*** 8360,8372 ****
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision must not be negative",
!                                         $3)));
                      if ($3 > MAX_INTERVAL_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
!                                         $3, MAX_INTERVAL_PRECISION)));
                          $3 = MAX_INTERVAL_PRECISION;
                      }
                      n->typename->typmod = INTERVAL_TYPMOD($3, $6);
--- 8360,8372 ----
                          ereport(ERROR,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision must not be negative",
!                                         (int)$3)));
                      if ($3 > MAX_INTERVAL_PRECISION)
                      {
                          ereport(WARNING,
                                  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                                   errmsg("INTERVAL(%d) precision reduced to maximum allowed, %d",
!                                         (int)$3, MAX_INTERVAL_PRECISION)));
                          $3 = MAX_INTERVAL_PRECISION;
                      }
                      n->typename->typmod = INTERVAL_TYPMOD($3, $6);
*** ./src/backend/parser/scan.l.orig    Sat Aug 12 23:04:58 2006
--- ./src/backend/parser/scan.l    Sat Aug 12 23:04:57 2006
***************
*** 666,671 ****
--- 666,690 ----
  #endif
                          )
                      {
+                                                 /* For Fetch/Move stmt, convert the string into int64 value */
+                                                 if((strcmp(yylval.keyword, "fetch")==0) || (strcmp(yylval.keyword,
"move")==0))
+                                                 {
+                                                         int64 intVal;
+                                                         errno = 0;
+
+                                                         intVal = strtoll(yytext, &endptr, 10);
+                                                         if (*endptr != '\0' || errno == ERANGE)
+                                                         {
+                                                                 yylval.str = pstrdup(yytext);
+                                                                 return FCONST;
+                                                         }
+                                                         else
+                                                         {
+                                                                 yylval.ival = intVal;
+                                                                 return ICONST;
+                                                         }
+                                                 }
+
                          /* integer too large, treat it as a float */
                          yylval.str = pstrdup(yytext);
                          return FCONST;
*** ./src/backend/tcop/postgres.c.orig    Sat Aug 12 23:05:03 2006
--- ./src/backend/tcop/postgres.c    Sat Aug 12 23:05:03 2006
***************
*** 1678,1684 ****
   * Process an "Execute" message for a portal
   */
  static void
! exec_execute_message(const char *portal_name, long max_rows)
  {
      CommandDest dest;
      DestReceiver *receiver;
--- 1678,1684 ----
   * Process an "Execute" message for a portal
   */
  static void
! exec_execute_message(const char *portal_name, int64 max_rows)
  {
      CommandDest dest;
      DestReceiver *receiver;
***************
*** 3263,3275 ****
              case 'E':            /* execute */
                  {
                      const char *portal_name;
!                     int            max_rows;

                      /* Set statement_timestamp() */
                      SetCurrentStatementStartTimestamp();

                      portal_name = pq_getmsgstring(&input_message);
!                     max_rows = pq_getmsgint(&input_message, 4);
                      pq_getmsgend(&input_message);

                      exec_execute_message(portal_name, max_rows);
--- 3263,3275 ----
              case 'E':            /* execute */
                  {
                      const char *portal_name;
!                     int64            max_rows;

                      /* Set statement_timestamp() */
                      SetCurrentStatementStartTimestamp();

                      portal_name = pq_getmsgstring(&input_message);
!                     max_rows = pq_getmsgint64(&input_message);
                      pq_getmsgend(&input_message);

                      exec_execute_message(portal_name, max_rows);
*** ./src/backend/tcop/pquery.c.orig    Sat Aug 12 23:05:03 2006
--- ./src/backend/tcop/pquery.c    Sat Aug 12 23:05:03 2006
***************
*** 37,45 ****
               ParamListInfo params,
               DestReceiver *dest,
               char *completionTag);
! static uint32 RunFromStore(Portal portal, ScanDirection direction, long count,
               DestReceiver *dest);
! static long PortalRunSelect(Portal portal, bool forward, long count,
                  DestReceiver *dest);
  static void PortalRunUtility(Portal portal, Query *query,
                   DestReceiver *dest, char *completionTag);
--- 37,45 ----
               ParamListInfo params,
               DestReceiver *dest,
               char *completionTag);
! static uint64 RunFromStore(Portal portal, ScanDirection direction, int64 count,
               DestReceiver *dest);
! static int64 PortalRunSelect(Portal portal, bool forward, int64 count,
                  DestReceiver *dest);
  static void PortalRunUtility(Portal portal, Query *query,
                   DestReceiver *dest, char *completionTag);
***************
*** 46,54 ****
  static void PortalRunMulti(Portal portal,
                 DestReceiver *dest, DestReceiver *altdest,
                 char *completionTag);
! static long DoPortalRunFetch(Portal portal,
                   FetchDirection fdirection,
!                  long count,
                   DestReceiver *dest);
  static void DoPortalRewind(Portal portal);

--- 46,54 ----
  static void PortalRunMulti(Portal portal,
                 DestReceiver *dest, DestReceiver *altdest,
                 char *completionTag);
! static int64 DoPortalRunFetch(Portal portal,
                   FetchDirection fdirection,
!                  int64 count,
                   DestReceiver *dest);
  static void DoPortalRewind(Portal portal);

***************
*** 545,551 ****
   * suspended due to exhaustion of the count parameter.
   */
  bool
! PortalRun(Portal portal, long count,
            DestReceiver *dest, DestReceiver *altdest,
            char *completionTag)
  {
--- 545,551 ----
   * suspended due to exhaustion of the count parameter.
   */
  bool
! PortalRun(Portal portal, int64 count,
            DestReceiver *dest, DestReceiver *altdest,
            char *completionTag)
  {
***************
*** 745,759 ****
   *
   * Returns number of rows processed (suitable for use in result tag)
   */
! static long
  PortalRunSelect(Portal portal,
                  bool forward,
!                 long count,
                  DestReceiver *dest)
  {
      QueryDesc  *queryDesc;
      ScanDirection direction;
!     uint32        nprocessed;

      /*
       * NB: queryDesc will be NULL if we are fetching from a held cursor or a
--- 745,759 ----
   *
   * Returns number of rows processed (suitable for use in result tag)
   */
! static int64
  PortalRunSelect(Portal portal,
                  bool forward,
!                 int64 count,
                  DestReceiver *dest)
  {
      QueryDesc  *queryDesc;
      ScanDirection direction;
!     uint64        nprocessed;

      /*
       * NB: queryDesc will be NULL if we are fetching from a held cursor or a
***************
*** 767,773 ****
      /*
       * Force the queryDesc destination to the right thing.    This supports
       * MOVE, for example, which will pass in dest = DestNone.  This is okay to
!      * change as long as we do it on every fetch.  (The Executor must not
       * assume that dest never changes.)
       */
      if (queryDesc)
--- 767,773 ----
      /*
       * Force the queryDesc destination to the right thing.    This supports
       * MOVE, for example, which will pass in dest = DestNone.  This is okay to
!      * change as int64 as we do it on every fetch.  (The Executor must not
       * assume that dest never changes.)
       */
      if (queryDesc)
***************
*** 806,817 ****

          if (!ScanDirectionIsNoMovement(direction))
          {
!             long        oldPos;

              if (nprocessed > 0)
                  portal->atStart = false;        /* OK to go backward now */
              if (count == 0 ||
!                 (unsigned long) nprocessed < (unsigned long) count)
                  portal->atEnd = true;    /* we retrieved 'em all */
              oldPos = portal->portalPos;
              portal->portalPos += nprocessed;
--- 806,817 ----

          if (!ScanDirectionIsNoMovement(direction))
          {
!             int64        oldPos;

              if (nprocessed > 0)
                  portal->atStart = false;        /* OK to go backward now */
              if (count == 0 ||
!                 (uint64) nprocessed < (uint64) count)
                  portal->atEnd = true;    /* we retrieved 'em all */
              oldPos = portal->portalPos;
              portal->portalPos += nprocessed;
***************
*** 854,860 ****
                  portal->portalPos++;    /* adjust for endpoint case */
              }
              if (count == 0 ||
!                 (unsigned long) nprocessed < (unsigned long) count)
              {
                  portal->atStart = true; /* we retrieved 'em all */
                  portal->portalPos = 0;
--- 854,860 ----
                  portal->portalPos++;    /* adjust for endpoint case */
              }
              if (count == 0 ||
!                 (uint64) nprocessed < (uint64) count)
              {
                  portal->atStart = true; /* we retrieved 'em all */
                  portal->portalPos = 0;
***************
*** 862,868 ****
              }
              else
              {
!                 long        oldPos;

                  oldPos = portal->portalPos;
                  portal->portalPos -= nprocessed;
--- 862,868 ----
              }
              else
              {
!                 int64        oldPos;

                  oldPos = portal->portalPos;
                  portal->portalPos -= nprocessed;
***************
*** 888,898 ****
   * are run in the caller's memory context (since we have no estate).  Watch
   * out for memory leaks.
   */
! static uint32
! RunFromStore(Portal portal, ScanDirection direction, long count,
               DestReceiver *dest)
  {
!     long        current_tuple_count = 0;
      TupleTableSlot *slot;

      slot = MakeSingleTupleTableSlot(portal->tupDesc);
--- 888,898 ----
   * are run in the caller's memory context (since we have no estate).  Watch
   * out for memory leaks.
   */
! static uint64
! RunFromStore(Portal portal, ScanDirection direction, int64 count,
               DestReceiver *dest)
  {
!     int64        current_tuple_count = 0;
      TupleTableSlot *slot;

      slot = MakeSingleTupleTableSlot(portal->tupDesc);
***************
*** 940,946 ****

      ExecDropSingleTupleTableSlot(slot);

!     return (uint32) current_tuple_count;
  }

  /*
--- 940,946 ----

      ExecDropSingleTupleTableSlot(slot);

!     return (uint64) current_tuple_count;
  }

  /*
***************
*** 1129,1141 ****
   *
   * Returns number of rows processed (suitable for use in result tag)
   */
! long
  PortalRunFetch(Portal portal,
                 FetchDirection fdirection,
!                long count,
                 DestReceiver *dest)
  {
!     long        result;
      Portal        saveActivePortal;
      Snapshot    saveActiveSnapshot;
      ResourceOwner saveResourceOwner;
--- 1129,1141 ----
   *
   * Returns number of rows processed (suitable for use in result tag)
   */
! int64
  PortalRunFetch(Portal portal,
                 FetchDirection fdirection,
!                int64 count,
                 DestReceiver *dest)
  {
!     int64        result;
      Portal        saveActivePortal;
      Snapshot    saveActiveSnapshot;
      ResourceOwner saveResourceOwner;
***************
*** 1244,1253 ****
   *
   * Returns number of rows processed (suitable for use in result tag)
   */
! static long
  DoPortalRunFetch(Portal portal,
                   FetchDirection fdirection,
!                  long count,
                   DestReceiver *dest)
  {
      bool        forward;
--- 1244,1253 ----
   *
   * Returns number of rows processed (suitable for use in result tag)
   */
! static int64
  DoPortalRunFetch(Portal portal,
                   FetchDirection fdirection,
!                  int64 count,
                   DestReceiver *dest)
  {
      bool        forward;
***************
*** 1283,1289 ****
                   * we are.    In any case, we arrange to fetch the target row
                   * going forwards.
                   */
!                 if (portal->posOverflow || portal->portalPos == LONG_MAX ||
                      count - 1 <= portal->portalPos / 2)
                  {
                      DoPortalRewind(portal);
--- 1283,1289 ----
                   * we are.    In any case, we arrange to fetch the target row
                   * going forwards.
                   */
!                 if (portal->posOverflow || portal->portalPos == LLONG_MAX ||
                      count - 1 <= portal->portalPos / 2)
                  {
                      DoPortalRewind(portal);
***************
*** 1293,1299 ****
                  }
                  else
                  {
!                     long        pos = portal->portalPos;

                      if (portal->atEnd)
                          pos++;    /* need one extra fetch if off end */
--- 1293,1299 ----
                  }
                  else
                  {
!                     int64        pos = portal->portalPos;

                      if (portal->atEnd)
                          pos++;    /* need one extra fetch if off end */
***************
*** 1405,1411 ****
       */
      if (!forward && count == FETCH_ALL && dest->mydest == DestNone)
      {
!         long        result = portal->portalPos;

          if (result > 0 && !portal->atEnd)
              result--;
--- 1405,1411 ----
       */
      if (!forward && count == FETCH_ALL && dest->mydest == DestNone)
      {
!         int64        result = portal->portalPos;

          if (result > 0 && !portal->atEnd)
              result--;
*** ./src/include/nodes/parsenodes.h.orig    Sat Aug 12 23:05:18 2006
--- ./src/include/nodes/parsenodes.h    Sat Aug 12 23:05:18 2006
***************
*** 1419,1431 ****
      FETCH_RELATIVE
  } FetchDirection;

! #define FETCH_ALL    LONG_MAX

  typedef struct FetchStmt
  {
      NodeTag        type;
      FetchDirection direction;    /* see above */
!     long        howMany;        /* number of rows, or position argument */
      char       *portalname;        /* name of portal (cursor) */
      bool        ismove;            /* TRUE if MOVE */
  } FetchStmt;
--- 1419,1431 ----
      FETCH_RELATIVE
  } FetchDirection;

! #define FETCH_ALL    LLONG_MAX

  typedef struct FetchStmt
  {
      NodeTag        type;
      FetchDirection direction;    /* see above */
!     int64        howMany;        /* number of rows, or position argument */
      char       *portalname;        /* name of portal (cursor) */
      bool        ismove;            /* TRUE if MOVE */
  } FetchStmt;
*** ./src/include/tcop/pquery.h.orig    Sat Aug 12 23:05:19 2006
--- ./src/include/tcop/pquery.h    Sat Aug 12 23:05:19 2006
***************
*** 30,42 ****
  extern void PortalSetResultFormat(Portal portal, int nFormats,
                        int16 *formats);

! extern bool PortalRun(Portal portal, long count,
            DestReceiver *dest, DestReceiver *altdest,
            char *completionTag);

! extern long PortalRunFetch(Portal portal,
                 FetchDirection fdirection,
!                long count,
                 DestReceiver *dest);

  #endif   /* PQUERY_H */
--- 30,42 ----
  extern void PortalSetResultFormat(Portal portal, int nFormats,
                        int16 *formats);

! extern bool PortalRun(Portal portal, int64 count,
            DestReceiver *dest, DestReceiver *altdest,
            char *completionTag);

! extern int64 PortalRunFetch(Portal portal,
                 FetchDirection fdirection,
!                int64 count,
                 DestReceiver *dest);

  #endif   /* PQUERY_H */
*** ./src/include/utils/portal.h.orig    Sat Aug 12 23:05:19 2006
--- ./src/include/utils/portal.h    Sat Aug 12 23:05:19 2006
***************
*** 163,169 ****
      bool        atStart;
      bool        atEnd;
      bool        posOverflow;
!     long        portalPos;

      /* Presentation data, primarily used by the pg_cursors system view */
      TimestampTz    creation_time;    /* time at which this portal was defined */
--- 163,169 ----
      bool        atStart;
      bool        atEnd;
      bool        posOverflow;
!     int64        portalPos;

      /* Presentation data, primarily used by the pg_cursors system view */
      TimestampTz    creation_time;    /* time at which this portal was defined */

pgsql-patches by date:

Previous
From: Hannu Krosing
Date:
Subject: Re: Forcing current WAL file to be archived
Next
From: Andrew Dunstan
Date:
Subject: Re: better support of out parameters in plperl