Re: A bad behavior under autocommit off mode

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: A bad behavior under autocommit off mode
Дата
Msg-id 200303241829.h2OITh522132@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: A bad behavior under autocommit off mode  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-hackers
OK, I have applied the following patch to fix the original bug report:

    psql -c "SET autocommit TO off;SELECT 1;COMMIT;" template1

It turns off grouping of queries into a single transaction when
autocommit is off, and documents that grouping behavior when autocommit
is on.  (It also removes a mention of porting from 6.4.)

This may get removed if we move autocommit to the client, but at least
it is done, and documented.

---------------------------------------------------------------------------

Bruce Momjian wrote:
> Tom Lane wrote:
> > Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > > The fix only changes the 'make it all one transaction' behavior.  It
> > > does not effect sending multiple queries in a string ---
> >
> > Yes it does!  The results may change.  Also the behavior if later
> > commands in the string fail will be different (roll back earlier
> > commands vs not).
>
> Right, people are using it, but do they even know that those are all one
> transaction?  I bet most don't.
>
> > > But I do think the roll-queries-into-one-transaction is
> > > strange and should be removed with the patch.
> >
> > I disagree.  This is long-established behavior and no one has complained
> > about it.  We have gone out of our way to preserve it in past changes;
> > I don't like suddenly deciding that backwards compatibility is
> > unimportant.  Especially not if only one person is in favor of the change.
>
> I asked for some votes.
>
> --
>   Bruce Momjian                        |  http://candle.pha.pa.us
>   pgman@candle.pha.pa.us               |  (610) 359-1001
>   +  If your life is a hard drive,     |  13 Roberts Road
>   +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: doc/src/sgml/libpq.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/libpq.sgml,v
retrieving revision 1.114
diff -c -c -r1.114 libpq.sgml
*** doc/src/sgml/libpq.sgml    22 Mar 2003 03:29:05 -0000    1.114
--- doc/src/sgml/libpq.sgml    24 Mar 2003 18:21:08 -0000
***************
*** 857,867 ****
  maintain the <structname>PGresult</structname> abstraction.  Use the accessor functions below to get
  at the contents of <structname>PGresult</structname>.  Avoid directly referencing the fields of the
  <structname>PGresult</structname> structure because they are subject to change in the future.
! (Beginning in <productname>PostgreSQL</productname> 6.4, the
! definition of <type>struct</> behind <structname>PGresult</> is not even provided in <filename>libpq-fe.h</>.  If you
! have old code that accesses <structname>PGresult</structname> fields directly, you can keep using it
! by including <filename>libpq-int.h</filename> too, but you are encouraged to fix the code
! soon.)
  </para>

  <variablelist>
--- 857,864 ----
  maintain the <structname>PGresult</structname> abstraction.  Use the accessor functions below to get
  at the contents of <structname>PGresult</structname>.  Avoid directly referencing the fields of the
  <structname>PGresult</structname> structure because they are subject to change in the future.
! If <quote>autocommit</quote> is on, multiple queries sent in a single
! function call are processed in a single transaction.
  </para>

  <variablelist>
Index: doc/src/sgml/ref/psql-ref.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/ref/psql-ref.sgml,v
retrieving revision 1.85
diff -c -c -r1.85 psql-ref.sgml
*** doc/src/sgml/ref/psql-ref.sgml    13 Feb 2003 05:37:43 -0000    1.85
--- doc/src/sgml/ref/psql-ref.sgml    24 Mar 2003 18:21:11 -0000
***************
*** 87,92 ****
--- 87,97 ----
        <application>psql</application>, like this: <literal>echo "\x \\
        select * from foo;" | psql</literal>.
        </para>
+       <para>
+       If <quote>autocommit</quote> is on, multiple queries in a single
+       string are processed in a single transaction.
+
+       </para>
        </listitem>
      </varlistentry>

Index: src/backend/tcop/postgres.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/tcop/postgres.c,v
retrieving revision 1.319
diff -c -c -r1.319 postgres.c
*** src/backend/tcop/postgres.c    22 Mar 2003 04:23:34 -0000    1.319
--- src/backend/tcop/postgres.c    24 Mar 2003 18:21:16 -0000
***************
*** 83,88 ****
--- 83,90 ----
  bool        Warn_restart_ready = false;
  bool        InError = false;

+ extern bool    autocommit;
+
  static bool EchoQuery = false;    /* default don't echo */

  /*
***************
*** 893,899 ****
           * historical Postgres behavior, we do not force a transaction
           * boundary between queries appearing in a single query string.
           */
!         if (lnext(parsetree_item) == NIL && xact_started)
          {
              finish_xact_command(false);
              xact_started = false;
--- 895,901 ----
           * historical Postgres behavior, we do not force a transaction
           * boundary between queries appearing in a single query string.
           */
!         if ((lnext(parsetree_item) == NIL || !autocommit) && xact_started)
          {
              finish_xact_command(false);
              xact_started = false;

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

Предыдущее
От: Dave Cramer
Дата:
Сообщение: Re: Please clarify with regard to Renaming a Sequence
Следующее
От: Robert Treat
Дата:
Сообщение: Re: [ADMIN] Regular expressions in PostgreSQL