Re: Patch for - Change FETCH/MOVE to use int8

Поиск
Список
Период
Сортировка
От Dhanaraj M
Тема Re: Patch for - Change FETCH/MOVE to use int8
Дата
Msg-id 44E6CA40.4090401@sun.com
обсуждение исходный текст
Ответ на Re: Patch for - Change FETCH/MOVE to use int8  (Alvaro Herrera <alvherre@commandprompt.com>)
Ответы Re: Patch for - Change FETCH/MOVE to use int8  (Bruce Momjian <bruce@momjian.us>)
Список pgsql-patches
Hi Alvaro

Thanks for your valuable suggestions.
I made the changes as suggested earlier.
Please review again and comment on this.
I like to make changes if it is required.
*** ./src/backend/commands/portalcmds.c.orig    Sat Aug 12 23:04:54 2006
--- ./src/backend/commands/portalcmds.c    Fri Aug 18 22:52:05 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 " INT64_FORMAT,
                   stmt->ismove ? "MOVE" : "FETCH",
                   nprocessed);
  }
*** ./src/backend/executor/spi.c.orig    Sat Aug 12 23:04:55 2006
--- ./src/backend/executor/spi.c    Fri Aug 18 02:14:20 2006
***************
*** 45,51 ****

  static void _SPI_error_callback(void *arg);

! static void _SPI_cursor_operation(Portal portal, bool forward, long count,
                        DestReceiver *dest);

  static _SPI_plan *_SPI_copy_plan(_SPI_plan *plan, int location);
--- 45,51 ----

  static void _SPI_error_callback(void *arg);

! static void _SPI_cursor_operation(Portal portal, bool forward, int64 count,
                        DestReceiver *dest);

  static _SPI_plan *_SPI_copy_plan(_SPI_plan *plan, int location);
***************
*** 980,986 ****
   *    Fetch rows in a cursor
   */
  void
! SPI_cursor_fetch(Portal portal, bool forward, long count)
  {
      _SPI_cursor_operation(portal, forward, count,
                            CreateDestReceiver(DestSPI, NULL));
--- 980,986 ----
   *    Fetch rows in a cursor
   */
  void
! SPI_cursor_fetch(Portal portal, bool forward, int64 count)
  {
      _SPI_cursor_operation(portal, forward, count,
                            CreateDestReceiver(DestSPI, NULL));
***************
*** 994,1000 ****
   *    Move in a cursor
   */
  void
! SPI_cursor_move(Portal portal, bool forward, long count)
  {
      _SPI_cursor_operation(portal, forward, count, None_Receiver);
  }
--- 994,1000 ----
   *    Move in a cursor
   */
  void
! SPI_cursor_move(Portal portal, bool forward, int64 count)
  {
      _SPI_cursor_operation(portal, forward, count, None_Receiver);
  }
***************
*** 1611,1620 ****
   *    Do a FETCH or MOVE in a cursor
   */
  static void
! _SPI_cursor_operation(Portal portal, bool forward, long count,
                        DestReceiver *dest)
  {
!     long        nfetched;

      /* Check that the portal is valid */
      if (!PortalIsValid(portal))
--- 1611,1620 ----
   *    Do a FETCH or MOVE in a cursor
   */
  static void
! _SPI_cursor_operation(Portal portal, bool forward, int64 count,
                        DestReceiver *dest)
  {
!     int64        nfetched;

      /* Check that the portal is valid */
      if (!PortalIsValid(portal))
*** ./src/backend/parser/gram.y.orig    Fri Aug 18 23:37:43 2006
--- ./src/backend/parser/gram.y    Fri Aug 18 01:12:58 2006
***************
*** 117,122 ****
--- 117,123 ----
  %union
  {
      int                ival;
+     int64                i64val;
      char                chr;
      char                *str;
      const char            *keyword;
***************
*** 323,328 ****
--- 324,330 ----
  %type <boolean> opt_varying opt_timezone

  %type <ival>    Iconst SignedIconst
+ %type <i64val>  SignedI64const
  %type <str>        Sconst comment_text
  %type <str>        RoleId opt_granted_by opt_boolean ColId_or_Sconst
  %type <list>    var_list var_list_or_default
***************
*** 446,451 ****
--- 448,454 ----
  /* Special token types, not actually keywords - see the "lex" file */
  %token <str>    IDENT FCONST SCONST BCONST XCONST Op
  %token <ival>    ICONST PARAM
+ %token <i64val> I64CONST

  /* precedence: lowest to highest */
  %nonassoc    SET                /* see relation_expr_opt_alias */
***************
*** 3334,3339 ****
--- 3337,3363 ----
                      n->howMany = $1;
                      $$ = (Node *)n;
                  }
+             | ABSOLUTE_P SignedI64const
+                                 {
+                                         FetchStmt *n = makeNode(FetchStmt);
+                                         n->direction = FETCH_ABSOLUTE;
+                                         n->howMany = $2;
+                                         $$ = (Node *)n;
+                                 }
+                         | RELATIVE_P SignedI64const
+                                 {
+                                         FetchStmt *n = makeNode(FetchStmt);
+                                         n->direction = FETCH_RELATIVE;
+                                         n->howMany = $2;
+                                         $$ = (Node *)n;
+                                 }
+                         | SignedI64const
+                                 {
+                                         FetchStmt *n = makeNode(FetchStmt);
+                                         n->direction = FETCH_FORWARD;
+                                         n->howMany = $1;
+                                         $$ = (Node *)n;
+                                 }
              | ALL
                  {
                      FetchStmt *n = makeNode(FetchStmt);
***************
*** 3355,3360 ****
--- 3379,3391 ----
                      n->howMany = $2;
                      $$ = (Node *)n;
                  }
+                         | FORWARD SignedI64const
+                                 {
+                                         FetchStmt *n = makeNode(FetchStmt);
+                                         n->direction = FETCH_FORWARD;
+                                         n->howMany = $2;
+                                         $$ = (Node *)n;
+                                 }
              | FORWARD ALL
                  {
                      FetchStmt *n = makeNode(FetchStmt);
***************
*** 3376,3381 ****
--- 3407,3419 ----
                      n->howMany = $2;
                      $$ = (Node *)n;
                  }
+                         | BACKWARD SignedI64const
+                                 {
+                                         FetchStmt *n = makeNode(FetchStmt);
+                                         n->direction = FETCH_BACKWARD;
+                                         n->howMany = $2;
+                                         $$ = (Node *)n;
+                                 }
              | BACKWARD ALL
                  {
                      FetchStmt *n = makeNode(FetchStmt);
***************
*** 8395,8400 ****
--- 8433,8441 ----
  SignedIconst: ICONST                                { $$ = $1; }
              | '-' ICONST                            { $$ = - $2; }
          ;
+ SignedI64const: I64CONST                                                          { $$ = $1; }
+                         | '-' I64CONST                                                { $$ = - $2; }
+                 ;

  /*
   * Name classification hierarchy.
*** ./src/backend/parser/scan.l.orig    Sat Aug 12 23:04:58 2006
--- ./src/backend/parser/scan.l    Fri Aug 18 23:01:04 2006
***************
*** 666,671 ****
--- 666,688 ----
  #endif
                          )
                      {
+                                             /* For Fetch/Move stmt, convert the string into int64 value */
+                                             if((strcmp(yylval.keyword, "fetch")==0) || (strcmp(yylval.keyword,
"move")==0))
+                                             {
+                                                     int64 int64Val;
+                                                     errno = 0;
+
+                                                     int64Val =  strtoll(yytext, &endptr, 10);
+                                                     if (*endptr != '\0' || errno == ERANGE)
+                                                     {
+                                                                 yylval.str = pstrdup(yytext);
+                                                                 return FCONST;
+                                                     }
+
+                                                     yylval.i64val = int64Val;
+                                                     return I64CONST;
+                                             }
+
                          /* 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    Fri Aug 18 01:18:47 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
***************
*** 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/executor/spi.h.orig    Sat Aug 12 23:05:17 2006
--- ./src/include/executor/spi.h    Fri Aug 18 02:13:15 2006
***************
*** 123,130 ****
  extern Portal SPI_cursor_open(const char *name, void *plan,
                  Datum *Values, const char *Nulls, bool read_only);
  extern Portal SPI_cursor_find(const char *name);
! extern void SPI_cursor_fetch(Portal portal, bool forward, long count);
! extern void SPI_cursor_move(Portal portal, bool forward, long count);
  extern void SPI_cursor_close(Portal portal);

  extern void AtEOXact_SPI(bool isCommit);
--- 123,130 ----
  extern Portal SPI_cursor_open(const char *name, void *plan,
                  Datum *Values, const char *Nulls, bool read_only);
  extern Portal SPI_cursor_find(const char *name);
! extern void SPI_cursor_fetch(Portal portal, bool forward, int64 count);
! extern void SPI_cursor_move(Portal portal, bool forward, int64 count);
  extern void SPI_cursor_close(Portal portal);

  extern void AtEOXact_SPI(bool isCommit);
*** ./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 по дате отправления:

Предыдущее
От: "Greg Sabino Mullane"
Дата:
Сообщение: Re: Information_schema fixes for sequences and temporary tables
Следующее
От: Gregory Stark
Дата:
Сообщение: Concurrent connections in psql patch