Re: [HACKERS] Review: ECPG FETCH readahead

2014-04-25 Thread Boszormenyi Zoltan

2014-04-24 15:19 keltezéssel, Boszormenyi Zoltan írta:

2014-04-24 14:50 keltezéssel, Michael Meskes írta:

Thanks an awful lot Antonin.


Committer availability might well be the issue, but missing review
probably too.
Yes, you're right. If my taks is mostly one last glance and a commit I will make time 
for that.



Whether this review is enough to move the patch to ready for committer
- I tend to let the next CFM decide. (I don't find it productive to
ignite another round of discussion about kinds of reviews - already saw
some.)

I saw some remarks in your review that Zoltan wants to address. Once I got the
updated version I'll have a look at it.

Zoltan, could you send a new version by end of day tomorrow? I'll be sitting on
a plane for a longer time again on Saturday. :)


I will try to.


Unfortunately, I won't make the deadline because of life
(I had to attend a funeral today) and because Antonin has
opened a can of worms with this comment:


* How about a regression test for the new ECPGcursor_dml() function?


There are some aspects that may need a new discussion.

The SQL standard wants an updatable cursor for positioned DML
(i.e. UPDATE/DELETE with the WHERE CURRENT OF clause)
This means passing FOR UPDATE in the query.

FOR UPDATE + SCROLL cursor is an impossible combination,
ERROR is thrown when DECLARE is executed. This combination can
(and should?) be detected in the ECPG preprocessor and it would
prevent runtime errors. It's not implemented at the moment.

Fortunately, a previous discussion resulted in explicitly passing
NO SCROLL for cursors where SCROLL is not specified, it's in 25.patch

I intend to extend it a little for SQL standard compliance with
embedded SQL. FOR UPDATE should also implicitly mean NO SCROLL.
Both the FOR UPDATE + explicit SCROLL and the explicit SCROLL +
usage of positioned DML can be detected in the preprocessor and
they should throw an error. Then the regression test would really make
sense.

But these checks in ECPG would still leave a big hole, and it's the other
DECLARE variant with the query passed in a prepared statement with
EXEC SQL PREPARE prep_stmt FROM :query_string;

Plugging this hole would require adding a simplified syntax checker to
libecpg that only checks the SelectStmt or re-adding the backend code
to tell the application the cursor's scrollable (and perhaps the updatable)
property.

I must have forgotten but surely this was the reason for changing the
DECLARE command tag in the first place which was shot down already.
So, only the other choice remains, the syntax checker in ecpglib.

I think implementing it would make the caching code miss 9.4, since
it adds a whole new set of code but the Perl magic for the ECPG syntax
checker may be mostly reusable here.

Best regards,
Zoltán Böszörményi



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Review: ECPG FETCH readahead

2014-04-24 Thread Boszormenyi Zoltan

2014-04-24 14:50 keltezéssel, Michael Meskes írta:

Thanks an awful lot Antonin.


Committer availability might well be the issue, but missing review
probably too.

Yes, you're right. If my taks is mostly one last glance and a commit I will 
make time for that.


Whether this review is enough to move the patch to ready for committer
- I tend to let the next CFM decide. (I don't find it productive to
ignite another round of discussion about kinds of reviews - already saw
some.)

I saw some remarks in your review that Zoltan wants to address. Once I got the
updated version I'll have a look at it.

Zoltan, could you send a new version by end of day tomorrow? I'll be sitting on
a plane for a longer time again on Saturday. :)


I will try to.

Thanks in advance,
Zoltán



Michael




--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Review: ECPG FETCH readahead

2014-04-23 Thread Boszormenyi Zoltan

it possible
504c504
  recommended to recompile using option option-r
readahead=number/option
---

  recommended to recompile it using option option-r

readahead=number/option


* src/interfaces/ecpg/ecpglib/extern.h

97c97
* The cursor was created in this level of * (sub-)transaction.
---

* The cursor was created at this level of (sub-)transaction.


* src/interfaces/ecpg/ecpglib/README.cursor+subxact

4c4
 Contents of tuples returned by a cursor always reflect the data present at
---

Contents of tuples returned by a cursor always reflects the data

present at


Contents of tuples ... reflect ...

Plural. The verb is correct as is. :-)


29c29
 needs two operations. If the next command issued by the application spills
---

need two operations. If the next command issued by the application spills


I'll re-read and see what context need is in. Hey, a context diff
would have made it more obvious. ;-)


32c32
 kinds of commands as is after 3 cache misses. FETCH FORWARD/BACKWARD
allows
---

kinds of commands as is after 3 cache misses. FETCH FORWARD/BACKWARD

allows
81c81
 I can also be negative (but also 1-based) if the application started with
---

It can also be negative (but also 1-based) if the application started with


Sure. This sentence is not about I but it's true either way. :-D


132c132
 is that (sub-)transactions are also needed to be tracked. These two are
---

is that (sub-)transactions also need to be tracked. These two are

148c148
 and he issued command may be executed without an error, causing unwanted
---

and the issued command may be executed without an error, causing unwanted


I will fix these.




In addition, please consider the following stuff in
src/interfaces/ecpg/ecpglib/README.cursor+subxact - it can't be
expressed as diff because I'm not 100% sure about the intended meaning


   either implicitly propagated - I'd expect either ... or  Or
remove no either at all?



   Committing a transaction or releasing a subtransaction make cursors ...
   -
   Committing a transaction or releasing a subtransaction propagates the
cursor(s) ... 
   ?



   The idea behind cursor readahead is to move one tuple less than asked
by the application ...

   My understanding of sql-cursor-ra-fetch.stderr is that the application
does not have to do MOVE explicitly. Maybe

   ... to move to the adjacent lower / upper tuple of the supposed
beginning of the result set and then have ecpglib perform FETCH FORWARD
/ BACKWARD N respectively ...

   Consider it just a tentative proposal, I can easily be wrong :-)


I will read your comments again with fresh eyes.



That's it for my review.


Thank you very much.



// Tony

On 04/16/2014 10:54 AM, Boszormenyi Zoltan wrote:

2014-01-18 18:08 keltezéssel, Boszormenyi Zoltan írta:

Hi,


Alvaro Herrera wrote:

Boszormenyi Zoltan escribió:

Rebased patches after the regression test and other details were fixed
in the infrastructure part.

This thread started in 2010, and various pieces have been applied
already and some others have changed in nature.  Would you please post a
new patchset, containing rebased patches that still need application, in
a new email thread to be linked in the commitfest entry?

I hope Thunderbird did the right thing and didn't include the reference
message ID when I told it to edit as new. So supposedly this is a new
thread but with all the cc: addresses kept.

I have rebased all remaining patches and kept the numbering.
All the patches from 18 to 25 that were previously in the
ECPG infrastructure CF link are included here.

There is no functional change.

Because of the recent bugfixes in the ECPG area, the patchset
didn't apply cleanly anymore. Rebased with no functional change.

Best regards,
Zoltán Böszörményi








--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] ECPG FETCH readahead

2014-04-16 Thread Boszormenyi Zoltan

2014-04-16 10:54 keltezéssel, Boszormenyi Zoltan írta:

2014-01-18 18:08 keltezéssel, Boszormenyi Zoltan írta:

Hi,


Alvaro Herrera wrote:

Boszormenyi Zoltan escribió:

Rebased patches after the regression test and other details were fixed
in the infrastructure part.


This thread started in 2010, and various pieces have been applied
already and some others have changed in nature.  Would you please post a
new patchset, containing rebased patches that still need application, in
a new email thread to be linked in the commitfest entry?


I hope Thunderbird did the right thing and didn't include the reference
message ID when I told it to edit as new. So supposedly this is a new
thread but with all the cc: addresses kept.

I have rebased all remaining patches and kept the numbering.
All the patches from 18 to 25 that were previously in the
ECPG infrastructure CF link are included here.

There is no functional change.


Because of the recent bugfixes in the ECPG area, the patchset
didn't apply cleanly anymore. Rebased with no functional change.


The patches themselves are a little bigger though. It's because the
patches are generated with 10 lines of context, this was set in my
$HOME/.gitconfig:

[diff]
context = 10

Best regards,
Zoltán Böszörményi



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] using arrays within structure in ECPG

2014-03-24 Thread Boszormenyi Zoltan

2014-03-24 07:22 keltezéssel, Ashutosh Bapat írta:

Hi,
I tried using integer array within a structure array in ECPG code. But it resulted in 
some garbage values being printed from the table. Here are the details,


The ECPG program is attached (array_test.pgc). It tries to read the contents of table 
emp, whose structure and contents are as follows

postgres=# \d+ emp
   Table public.emp
 Column  |   Type| Modifiers | Storage  | Stats target | Description
-+---+---+--+--+-
 empno   | numeric(4,0)  |   | main |  |
 ename   | character varying |   | extended |  |
 job | character varying |   | extended |  |
 arr_col | integer[] |   | extended |  |
Has OIDs: no

postgres=# select * from emp;
 empno | ename  |   job   |  arr_col
---++-+
  7900 | JAMES  | CLERK   | {1,2,7900}
  7902 | FORD   | ANALYST | {1,2,7902}
  7934 | MILLER | CLERK   | {1,2,7934}
(3 rows)

You will notice that the last element of the arr_col array is same as the empno of that 
row.


The ECPG program tries to read the rows using FETCH in a structure emp defined 
as
 15 struct employee {
 16 int empno;
 17char ename[11];
 18char job[15];
 19int  arr_col[3];
 20 };

and then print the read contents as
 39 /* Print members of the structure. */
 40 for ( i = 0 ;i  3; i++){
 41 printf(empno=%d, ename=%s, job=%s, arr_col[2]=%d\n, emp[i].empno, 
emp[i].ename, emp[i].job, emp[i].arr_col[2]);

 42
 43 }

But garbage values are printed
[ashutosh@ubuntu repro]./array_test

+++
empno=7900, ename=JAMES, job=CLERK, arr_col[2]=1
empno=2, ename=�, job=ANALYST, arr_col[2]=32767
empno=7934, ename=MILLER, job=CLERK, arr_col[2]=1719202336

Here are steps I have used to compile the ECPG program
[ashutosh@ubuntu repro]make array_test
ecpg -c -I/work/pg_head/build/include array_test.pgc
cc -I/work/pg_head/build/include -g   -c -o array_test.o array_test.c
cc -g  array_test.o  -L/work/pg_head/build/lib -lecpg -lpq -o array_test
rm array_test.o array_test.c

where /work/pg_head/build is the directory containing the postgresql build (essentially 
argument to the --prefix option to configure).


The programs compiles and links fine.

Without the arr_col member, the program works fine. So, it seems to be a problem with 
array within structure array.


In array_test.c I see that the ECPGdo statement corresponding to the FETCH command is as 
follows

 87 /* Fetch multiple columns into one structure. */
 88 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, fetch 3 from cur1, 
ECPGt_EOIT,
 89 ECPGt_int,(emp-empno),(long)1,(long)14,sizeof( struct employee ),
 90 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
 91 ECPGt_char,(emp-ename),(long)11,(long)14,sizeof( struct employee ),
 92 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
 93 ECPGt_char,(emp-job),(long)15,(long)14,sizeof( struct employee ),
 94 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
 95 ECPGt_int,(emp-arr_col),(long)1,(long)3,sizeof(int),
 96 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);

For all the members of struct employee, except arr_col, the size of array is set to 14 
and next member offset is set of sizeof (struct employee). But for arr_col they are set 
to 3 and sizeof(int) resp. So, for the next row onwards, the calculated offset of 
arr_col member would not coincide with the real arr_col member's address.


Am I missing something here?


ECPG (I think intentionally) doesn't interpret or parse array fields.
You need to pass a character array and parse the contents by yourself.

Best regards,
Zoltán Böszörményi


--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company






Re: Review: [HACKERS] ECPG infrastructure changes part 1, was: Re: ECPG fixes

2014-01-17 Thread Boszormenyi Zoltan

2014-01-16 22:13 keltezéssel, Alvaro Herrera írta:

Alvaro Herrera escribió:

Boszormenyi Zoltan escribió:


All patches are attached again for completeness.

Thanks.  I pushed a commit comprising patches 09 through 14.

Now also pushed 15 to 17.


Thanks very much.



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] ECPG FETCH readahead, was: Re: ECPG fixes

2014-01-17 Thread Boszormenyi Zoltan

2014-01-16 23:42 keltezéssel, Alvaro Herrera írta:

Boszormenyi Zoltan escribió:

Rebased patches after the regression test and other details were fixed
in the infrastructure part.

This thread started in 2010, and various pieces have been applied
already and some others have changed in nature.  Would you please post a
new patchset, containing rebased patches that still need application, in
a new email thread to be linked in the commitfest entry?


I will do that.

Best regards,
Zoltán Böszörményi



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [bug fix] ECPG app crashes due to SIGBUS on SPARC Solaris

2013-12-24 Thread Boszormenyi Zoltan
2013-12-24 13:55 kelteze'ssel, MauMau i'rta:
 Hello,

 I encountered a bug of ECPG with PG 9.2.4, which probably exists in all 
 releases. The
 attached patch is for 9.4. Could you review and backport this to at least 9.2 
 and later?


 [Problem]
 The attached ECPG app

The app wasn't attached, only the patch.
If this is a small test app, it can also be a part of the patch in the form of a
regression test.

 crashes and dumps core with SIGBUS on Solaris for SPARC. I used Solaris 10, 
 and Oracle
 Studio to compile the app for 64-bit build. The same app completes 
 successfully on Linux
 and Windows for x86/x564.

 The steps to reproduce the problem is:
 1. ecpg sigbus.pgc
 2. cc -xtarget=generic64 -Ipgsql_dir/include sigbus.c -Lpgsql_dir/lib 
 -lecpg
 3. a.out

 When execting FETCH statement using an SQL descriptor, the app crashes at the 
 following
 line in ECPGdo(), which is in src/interfaces/ecpg/ecpglib/execute.c:

 var-value = *((char **) (var-pointer));


 [Cause]
 ecpg outputs the following line in the preprocessed source file:

 { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, fetch $0,
 ECPGt_char,(cur),(long)4,(long)1,(4)*sizeof(char),
 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
 ECPGt_descriptor, (desc1), 0L, 0L, 0L,
 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);}

 So, the above line is executed in ECPGdo(). On the other hand, desc1 is not 
 aligned on
 8-byte boundary. This unaligned access causes SIGBUS.


 [Fix]
 Because desc1 is a char array, else block should be executed instead of the 
 above path.

 var-value = var-pointer;

 Therefore, make ecpg pass SQL descriptor host variables to ECPGdo() with 
 non-zero lengths.


 Regards
 MauMau




-- 
--
Zolta'n Boszorme'nyi
Cybertec Schonig  Schonig GmbH
Grohrmuhlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] ECPG FETCH readahead, was: Re: ECPG fixes

2013-12-23 Thread Boszormenyi Zoltan

2013-12-21 14:56 keltezéssel, Peter Eisentraut írta:

This patch didn't make it out of the 2013-11 commit fest.  You should
move it to the next commit fest (probably with an updated patch)
before January 15th.


Done.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Backup throttling

2013-12-06 Thread Boszormenyi Zoltan

Hi,

2013-12-05 15:36 keltezéssel, Antonin Houska írta:

On 12/02/2013 02:23 PM, Boszormenyi Zoltan wrote:

Hi,

I am reviewing your patch.

Thanks. New version attached.


I have reviewed and tested it and marked it as ready for committer.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: Review: [HACKERS] ECPG infrastructure changes part 1, was: Re: ECPG fixes

2013-12-03 Thread Boszormenyi Zoltan

Thanks for the review.

2013-12-03 16:48 keltezéssel, Antonin Houska írta:

The changes are very well divided into logical units, so I think I could
understand the ideas. I'm not too familiar with the ecpg internals, so
consider this at least a coding review.


git apply:  Clean, except for one finding below

Build:  no errors/warnings

Documentation build: no errors/warnings. The changes do appear in ecpg.html.

Regression tests: all passed

Non-Linux platforms: I can't verify, but I haven't noticed any new
dependencies added.

Comments (in the source code): good.


(My) additional comments:


22.patch


tuples_left  0

instead of just

tuples_left

seems to me safer in for-loops. Not sure if there's a convention for
this though.


I'll look at it, maybe the 0 had a reason.



23.patch


git apply --verbose ~/cybertec/patches/ecpq/23.patch
/home/anton/cybertec/patches/ecpq/23.patch:494: space before tab in indent.
 /*--
/home/anton/cybertec/patches/ecpq/23.patch:495: space before tab in indent.
translator: this string will be truncated at
149 characters expanded.  */
/home/anton/cybertec/patches/ecpq/23.patch:4019: trailing whitespace.
 exec sql close :curname;


I will fix the extra spaces.


Tests - 23.patch


src/interfaces/ecpg/test/sql/cursorsubxact.pgc


 /*
  * Test the implicit RELEASE SAVEPOINT if a SAVEPOINT
  * is used with an already existing name.
  */

Shouldn't it be ... if a CURSOR is used with an already existing
name?. Or just ... implicit RELEASE SAVEPOINT after an error?
I'd also appreciate a comment where exactly the savepoint is
(implicitly) released.


If you do this:

SAVEPOINT A;
some operations
SAVEPOINT A; /* same savepoint name */

then the operations between the two are implicitly committed
to the higher subtransaction, i.e. it works as if there was a
RELEASE SAVEPOINT A; before the second SAVEPOINT A;
It happens to be tested with a DECLARE CURSOR statement
and the runtime has to refresh its knowledge about the cursor
by propagating it into a subtransaction one level higher.


23.patch and 24.patch
-

SO_MAJOR_VERSION and also interfaces/ecpg/include/ecpglib.h is changed

Thus all client applications probably need to be preprocessed  compiled
against the PG 9.4. I don't know how this is usually enforced. I'm
mentioning it for the sake of completeness.


The soversion has changed because of the changes in already
existing exported functions.



// Antonin Houska (Tony)


On 11/28/2013 03:21 PM, Boszormenyi Zoltan wrote:

2013-11-20 14:53 keltezéssel, Boszormenyi Zoltan írta:

2013-11-20 14:41 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:15 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:01 keltezéssel, Noah Misch írta:

On Mon, Nov 11, 2013 at 10:17:54AM +0100, Boszormenyi Zoltan wrote:

The old contents of my GIT repository was removed so you need to
clone it fresh. https://github.com/zboszor/ecpg-readahead.git
I won't post the humongous patch again, since sending a 90KB
compressed file to everyone on the list is rude.

Patches of that weight show up on a regular basis.  I don't think it's rude.

OK, here it is.

...
Subsequent patches will come as reply to this email.

Infrastructure changes in ecpglib/execute.c to split up
ECPGdo and ecpg_execute() and expose the parts as
functions internal to ecpglib.

Rebased after killing the patch that changed the DECLARE CURSOR command tag.
All infrastructure patches are attached, some of them compressed.

Best regards,
Zoltán Böszörményi







--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Backup throttling

2013-12-02 Thread Boszormenyi Zoltan

Hi,

I am reviewing your patch.

2013-10-10 15:32 keltezéssel, Antonin Houska írta:

On 10/09/2013 08:56 PM, Robert Haas wrote:

There seem to be several review comments made since you posted this
version.  I'll mark this Waiting on Author in the CommitFest
application, since it seems that the patch needs to be further
updated.

Since it was waiting for reviewer, I was not sure whether I should wait
for his findings and fix everything in a single transaction.
Nevertheless, the next version is attached here.

It fixes findings reported in
http://www.postgresql.org/message-id/20130903165652.gc5...@eldon.alvh.no-ip.org

As for units
http://www.postgresql.org/message-id/20130903224127.gd7...@awork2.anarazel.de
I'm not convinced about MB at the moment. Unfortunately I couldn't
find any other command-line PG utility requiring amount of data as an
option. Thus I use single-letter suffix, just as wget does for the same
purposes.

As for this
http://www.postgresql.org/message-id/20130903125155.ga18...@awork2.anarazel.de
there eventually seems to be a consensus (I notice now the discussion
was off-list):


On 2013-09-03 23:21:57 +0200, Antonin Houska wrote:

On 09/03/2013 02:51 PM, Andres Freund wrote:


It's probably better to use latches for the waiting, those have properly
defined interruption semantics. Whether pg_usleep will be interrupted is
platform dependant...

I noticed a comment about interruptions around the definition of
pg_usleep() function, but concluded that the sleeps are rather frequent
in this applications (typically in the order of tens to hundreds per
second, although the maximum of 256 might need to be decreased).
Therefore occasional interruptions shouldn't distort the actual rate
much. I'll think about it again. Thanks,

The issue is rather that you might not get woken up when you want to
be. Signal handlers in postgres tend to do a
SetLatch(MyProc-procLatch); which then will interrupt sleeps done via
WaitLatch(). It's probably not that important with the duration of the
sleeps you have.

Greetings,

Andres Freund

// Antonin Houska (Tony)


* Is the patch in a patch format which has context?

Yes

* Does it apply cleanly to the current git master?

It applies with some offsets. Version 3a that applies cleanly is attached.

* Does it include reasonable tests, necessary doc patches, etc?

Docs: yes. Tests: N/A

* Does the patch actually implement what it advertises?

Yes.

* Do we want that?

Yes.

* Do we already have it?

No.

* Does it follow SQL spec, or the community-agreed behavior?

No such SQL spec. The latest patch fixed all previously raised comments.

* Does it include pg_dump support (if applicable)?

N/A

* Are there dangers?

Yes, the danger of slowing down taking a base backup.
But this is the point.

* Have all the bases been covered?

Yes.

* Does the feature work as advertised?

Yes.

* Are there corner cases the author has failed to consider?

No.

* Are there any assertion failures or crashes?

No.

* Does the patch slow down simple tests?

No.

* If it claims to improve performance, does it?

N/A

* Does it slow down other things?

No.

* Does it follow the project coding guidelines?

Yes. A nitpicking: this else branch below might need brackets
because there is also a comment in that branch:

+   /* The 'real data' starts now (header was ignored). */
+   throttled_last = GetCurrentIntegerTimestamp();
+   }
+   else
+   /* Disable throttling. */
+   throttling_counter = -1;
+

* Are there portability issues?

No.

* Will it work on Windows/BSD etc?

It should, there are no dangerous calls besides the above mentioned
pg_usleep(). But waking up from pg_usleep() earlier makes rate limiting
fluctuate slightly, not fail.

* Are the comments sufficient and accurate?

Yes.

* Does it do what it says, correctly?

Yes.

Although it should be mentioned in the docs that rate limiting
applies to walsenders individually, not globally. I tried this
on a freshly created database:

$ time pg_basebackup -D data2 -r 1M -X stream -h 127.0.0.1
real0m26.508s
user0m0.054s
sys0m0.360s

The source database had 3 WAL files in pg_xlog, one of them was
also streamed. The final size of data2 was 43MB or 26MB without pg_xlog,
i.e. without the -X stream option. The backup used 2 walsenders
in parallel (one for WAL) which is a known feature.

* Does it produce compiler warnings?

No.

*Can you make it crash?

No.

Consider the changes to the code in the context of the project as a whole:

* Is everything done in a way that fits together coherently with other 
features/modules?

Yes.

* Are there interdependencies that can cause problems?

No.

Another note. This chunk should be submitted separately as a comment bugfix:

diff --git a/src/backend/utils/adt/timestamp.c 
b/src/backend/utils/adt/timestamp.c
index c3c71b7..5736fd8 100644
--- a/src/backend/utils/adt/timestamp.c
+++ 

Re: [HACKERS] Modify the DECLARE CURSOR command tag depending on the scrollable flag

2013-11-28 Thread Boszormenyi Zoltan

2013-11-28 00:17 keltezéssel, Tom Lane írta:

Peter Eisentraut pete...@gmx.net writes:

On 11/27/13, 3:47 PM, Tom Lane wrote:

Given these considerations, I think it'd be better to allow explicit
application control over whether read-ahead happens for a particular
query.  And I have no problem whatsoever with requiring that the cursor
be explicitly marked SCROLL or NO SCROLL before read-ahead will occur.

Well, technically, unspecified means NO SCROLL according to the SQL
standard.  A lot of applications in ECPG are ported from other systems,
which might make that assumption.  It wouldn't be very nice to have to
change all that.

Hm.  So you're suggesting that ECPG fix this problem by inserting an
explicit NO SCROLL clause into translated DECLARE CURSOR commands, if
there's not a SCROLL clause?

That would solve the problem of the ECPG library not being sure which
behavior applies, but it might break existing apps that were unknowingly
relying on a simple cursor being scrollable.  OTOH any such app would be
subject to breakage anyway as a result of planner changes, so it's hard to
complain against this, as long as it's happening in a major version
update.

I'm for it.


If all such apps are expected to be ported from other system,
then yes, that would also work. However, I am not so sure about this.

One thing is sure. With this change, ecpglib can still work with
older PostgreSQL versions but the application's behaviour changes
if the cursor doesn't have an explicit SCROLL/NO SCROLL.

In my first mail yesterday, I wrote such a code has always been
buggy and should be fixed and I meant it seriously.

I was only half serious with ripping this support code out of the backend.
However, this feature might be deprecated and removed in about
3 major release or what the usual policy is. Inconsistency between
different clients is also no good. You can only enforce similar client
behaviour with the server behaviour.

Anyway, is explicitly adding NO SCROLL the preferred solution for everyone?

Best regards,
Zoltán Böszörményi



regards, tom lane




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Modify the DECLARE CURSOR command tag depending on the scrollable flag

2013-11-28 Thread Boszormenyi Zoltan

2013-11-28 09:55 keltezéssel, Michael Meskes írta:

On Thu, Nov 28, 2013 at 09:04:17AM +0100, Boszormenyi Zoltan wrote:

Well, technically, unspecified means NO SCROLL according to the SQL
standard.  A lot of applications in ECPG are ported from other systems,

That means by automatically adding a literal NO SCROLL to the command we obey
standard, right? That's fine by me.


behavior applies, but it might break existing apps that were unknowingly
relying on a simple cursor being scrollable.  OTOH any such app would be
subject to breakage anyway as a result of planner changes, so it's hard to
complain against this, as long as it's happening in a major version
update.

Ported applications might be in the same boat. I'm not sure if all other DBMSs
stick with the standard if nothing is specified. So again, adding it might help
make it clearer.


Anyway, is explicitly adding NO SCROLL the preferred solution for everyone?

+1 from me.


Thanks, I will rework the patches this way.



Michael



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Modify the DECLARE CURSOR command tag depending on the scrollable flag

2013-11-28 Thread Boszormenyi Zoltan

2013-11-29 04:56 keltezéssel, Peter Eisentraut írta:

On Wed, 2013-11-27 at 18:17 -0500, Tom Lane wrote:

Hm.  So you're suggesting that ECPG fix this problem by inserting an
explicit NO SCROLL clause into translated DECLARE CURSOR commands, if
there's not a SCROLL clause?

I wouldn't go that far yet.

Do I understand this right that the future readahead code needs separate
behavior depending on whether a cursor is scrollable?


The same code is used.

However, when the cursor is not scrollable, it returns an error early
to the application when it wants to go backward. It still allows
FETCH/MOVE ABSOLUTE to an earlier position just like the backend,
in which case scanning the cursor is restarted from the beginning.

If the cursor is not scrollable, the readahead code must not serve
tuples from the currently populated cache backward. If the cursor
is scrollable, FETCH BACKWARD is served from the cache.


   I would think
that whatever you do with NO SCROLL cursors would also work with SCROLL
cursors, so if you don't know what the cursor is, just use the code for
NO SCROLL.







--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Modify the DECLARE CURSOR command tag depending on the scrollable flag

2013-11-27 Thread Boszormenyi Zoltan

2013-11-23 22:01 keltezéssel, Tom Lane írta:

Boszormenyi Zoltan z...@cybertec.at writes:

Attached is the patch that modified the command tag returned by
the DECLARE CURSOR command. It returns DECLARE SCROLL CURSOR
or DECLARE NO SCROLL CURSOR depending on the cursor's
scrollable flag that can be determined internally even if neither is
asked explicitly.

This does not strike me as an acceptable change.  It will break any code
that's expecting the existing command tag, for little or no benefit
to most applications.  Even if backwards compatibility were of no concern,
I'm not convinced it's a good thing to expose the backend's internal
choices about query plans used for cursors, which is what this is
basically doing.


I saw code in the backend allowing a cursor to be scrollable, although
it was not declared as such. How about ripping that out?

That way there would be no incentive for lazy SQL coding using simple cursors.

You can argue that it would also break application compatibility but
on the other hand, such a code has always been buggy and should be fixed.


It is expected by the ECPG cursor readahead code.

And that doesn't sound like a sufficient excuse.  You should only assume a
cursor is scrollable if SCROLL was specified in the cursor declaration
command, which it'd seem to me is something ECPG would or easily could
know about commands it issues.


Yes, it can and I have a patch in the series passing this info to ecpglib.

I am also arguing for backward compatibility on a different angle:
this small backend change would still allow using simple cursors
in ECPG while using the cursor readahead.

And it's not the first time drivers have to adapt to new PostgreSQL major 
versions.
If it was, I wouldn't have the courage to set a precedent either.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Modify the DECLARE CURSOR command tag depending on the scrollable flag

2013-11-27 Thread Boszormenyi Zoltan

2013-11-27 19:16 keltezéssel, Tom Lane írta:

Boszormenyi Zoltan z...@cybertec.at writes:

2013-11-23 22:01 keltezéssel, Tom Lane írta:

Boszormenyi Zoltan z...@cybertec.at writes:

Attached is the patch that modified the command tag returned by
the DECLARE CURSOR command. It returns DECLARE SCROLL CURSOR
or DECLARE NO SCROLL CURSOR depending on the cursor's
scrollable flag that can be determined internally even if neither is
asked explicitly.

This does not strike me as an acceptable change.  It will break any code
that's expecting the existing command tag, for little or no benefit
to most applications.  Even if backwards compatibility were of no concern,
I'm not convinced it's a good thing to expose the backend's internal
choices about query plans used for cursors, which is what this is
basically doing.

I saw code in the backend allowing a cursor to be scrollable, although
it was not declared as such. How about ripping that out?

That also fails the unnecessary-backwards-compatibility-break test.


If you read the rest of the mail, it turns out it wasn't a serious question.

Getting the SCROLL / NO SCROLL flags from the preprocessor is no problem.
The only problem is when it's unspecified.

Treating it as NO SCROLL (or adding it to the DECLARE command behind
the application's back) would break apps that want to scroll backward.
(Not ABSOLUTE.)

On the other hand, what problems would one face when adding SCROLL
implicitly if it's unspecified? It's not a workable solution either, see below.

As the documentation suggests, an application that wants to use
UPDATE/DELETE WHERE CURRENT OF ..., it's highly recommended
that the cursor is for a FOR UPDATE query. Watch this scenario:

zozo= begin;
BEGIN
zozo= declare mycur cursor for select * from t1 for update;
DECLARE CURSOR
zozo= fetch from mycur;
 id | t
+---
  1 | a
(1 row)

zozo= fetch from mycur;
 id | t
+---
  2 | b
(1 row)

zozo= update t1 set t=t||'_x' where current of mycur;
UPDATE 1
zozo= fetch from mycur;
 id | t
+---
  3 | c
(1 row)

zozo= delete from t1 where current of mycur;
DELETE 1
zozo= move absolute 0 in mycur;
MOVE 0
zozo= fetch from mycur;
 id | t
+---
  1 | a
(1 row)

zozo= fetch from mycur;
 id | t
+---
(0 rows)

Although the server complains about MOVE BACKWARD, it's not
complaining about MOVE ABSOLUTE, despite it's clearly moving
backward. The cursor position is tracked in the backend in a long
variable and it's not overflowed. This is also legacy behaviour,
changing it would break backward compatibility.

The other problem I see is with the documentation: it says that
the INSENSITIVE keyword is just a placeholder, all cursors are insensitive.
It's clearly false. Moving back to the start, previously existing rows
won't show up again. It's not strictly a sensitive cursor, either,
because the row with id=2 would show up with the new value of t.
This neither sensitive nor insensitive behaviour is what the SQL
standard calls an asensitive cursor. It would worth a doc change.
This is what's written in 9.3:


If the cursor's query includes FOR UPDATE or FOR SHARE, then returned rows are locked at 
the time they are first fetched, in the same way as for a regular SELECT 
http://www.postgresql.org/docs/9.3/interactive/sql-select.html command with these 
options. In addition, the returned rows will be the most up-to-date versions; therefore 
these options provide the equivalent of what the SQL standard calls a sensitive cursor. 
(Specifying INSENSITIVE together with FOR UPDATE or FOR SHARE is an error.)


( http://www.postgresql.org/docs/9.3/interactive/sql-declare.html )

However, if the cursor is declared without FOR UPDATE, both
the explicit SCROLL keyword (or implicit, if the query is simple),
scrolling backward and DML with WHERE CURRENT OF are allowed.
In this case, the cursor is really insensitive, FETCH statements
after MOVE ABSOLUTE 0 return all rows with their original data.

This is just to show that adding SCROLL behind the application's
back is also pointless. If the query (which can also be a prepared
statement in ECPG) contains FOR UPDATE, adding SCROLL to the
DECLARE statement would make it fail.

If you consider all these:

- certain combinations of query and DECLARE stmt flags fail;
- adding NO SCROLL is breaking backward compatibility;
- the readahead code has to really know whether the cursor is
  scrollable so it can behave just like the server;

then returning the SCROLL / NO SCROLL flag in the command tag is
not a bad solution in my view. In fact, this was the only workable
solution I could come up with to make it work reliably when neither
SCROLL nor NO SCROLL is specified by the application.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] Modify the DECLARE CURSOR command tag depending on the scrollable flag

2013-11-27 Thread Boszormenyi Zoltan

2013-11-27 20:49 keltezéssel, Alvaro Herrera írta:

Boszormenyi Zoltan escribió:


If you consider all these:

- certain combinations of query and DECLARE stmt flags fail;
- adding NO SCROLL is breaking backward compatibility;
- the readahead code has to really know whether the cursor is
   scrollable so it can behave just like the server;

then returning the SCROLL / NO SCROLL flag in the command tag is
not a bad solution in my view. In fact, this was the only workable
solution I could come up with to make it work reliably when neither
SCROLL nor NO SCROLL is specified by the application.

Would it work to have a function of some sort to which you give a cursor
name and it returns whether it is scrollable or not?


D'oh. Yes, that would also work. Thanks for the idea. :-)
I will implement it and adapt my remaining patches.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] b21de4e7b32f868a23bdc5507898d36cbe146164 seems to be two bricks shy of a load

2013-11-21 Thread Boszormenyi Zoltan

2013-11-21 11:52 keltezéssel, David Rowley írta:
I'm not quite sure why nobody else seems to be complaining, but the changes to type.h in 
this commit seems to have broken things little.


In the visual studios build I'm getting:

  src\interfaces\ecpg\preproc\preproc.y(84): error C2065: 'ET_FATAL' : undeclared 
identifier [D:\Postgres\b\ecpg.vcxproj]
  src\interfaces\ecpg\preproc\preproc.y(84): error C2051: case expression not constant 
[D:\Postgres\b\ecpg.vcxproj]
  src\interfaces\ecpg\preproc\preproc.y(102): error C2065: 'ET_FATAL' : undeclared 
identifier [D:\Postgres\b\ecpg.vcxproj]
  src\interfaces\ecpg\preproc\preproc.y(102): error C2051: case expression not constant 
[D:\Postgres\b\ecpg.vcxproj]
  src\interfaces\ecpg\preproc\preproc.y(14664): error C2065: 'ET_FATAL' : undeclared 
identifier [D:\Postgres\b\ecpg.vcxproj]


Which I'm guessing is something to do with:

--- a/src/interfaces/ecpg/preproc/type.h 
http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/interfaces/ecpg/preproc/type.h;h=b7768fd66146e16547f385d30272e2a42e4d6832;hb=b7768fd66146e16547f385d30272e2a42e4d6832
+++ b/src/interfaces/ecpg/preproc/type.h 
http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/interfaces/ecpg/preproc/type.h;h=cd0d1da8c4a1a641acd9f6b6b7dfa88e7241394d;hb=cd0d1da8c4a1a641acd9f6b6b7dfa88e7241394d
@@ -186,7 
http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/interfaces/ecpg/preproc/type.h;h=b7768fd66146e16547f385d30272e2a42e4d6832;hb=b7768fd66146e16547f385d30272e2a42e4d6832#l186 
+186,7 
http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/interfaces/ecpg/preproc/type.h;h=cd0d1da8c4a1a641acd9f6b6b7dfa88e7241394d;hb=cd0d1da8c4a1a641acd9f6b6b7dfa88e7241394d#l186 
@@ struct assignment

 enum errortype
 {
-   ET_WARNING, ET_ERROR, ET_FATAL
+   ET_WARNING, ET_ERROR
 };


Regards

David Rowley


You should regenerate preproc.y.
./configure --enable-depend does the trick under Linux
but I don't know how to do it under Windows.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



ECPG fixes, was: Re: [HACKERS] ECPG FETCH readahead

2013-11-20 Thread Boszormenyi Zoltan

2013-11-12 07:15 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:01 keltezéssel, Noah Misch írta:

On Mon, Nov 11, 2013 at 10:17:54AM +0100, Boszormenyi Zoltan wrote:

The old contents of my GIT repository was removed so you need to
clone it fresh. https://github.com/zboszor/ecpg-readahead.git
I won't post the humongous patch again, since sending a 90KB
compressed file to everyone on the list is rude.

Patches of that weight show up on a regular basis.  I don't think it's rude.


OK, here it is.


I have rebased the patchset after ecpg: Split off mmfatal() from mmerror()
since it caused merge conflicts.

It's at the usual place again, you need to clone it from scratch if you are
interested in looking at git diff/log

I have removed some previous ecpg_log() debug output and
the total patch size is not so huge any more but I am going to post
the split-up set in parts.

Attached is the first few patches that are strictly generic ECPG fixes.
They can be applied independently and obvious enough.

Subsequent patches will come as reply to this email.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

commit f167aaa9693305e08cd6b2946af8528dada799b4
Author: Böszörményi Zoltán z...@cybertec.at
Date:   Wed Nov 20 10:31:21 2013 +0100

ECPG: Make the preprocessor emit ';' if the variable type for
a list of variables is varchar. This fixes this test case:

int main(void)
{
exec sql begin declare section;
varchar a[50], b[50];
exec sql end declare section;

return 0;
}

Since varchars are internally turned into custom structs and
the type name is emitted for these variable declarations,
the preprocessed code previously had:

struct varchar_1  { ... }  a _,_  struct varchar_2  { ... }  b ;

The comma in the generated C file was a syntax error.

There are no regression test changes since it's not exercised.

diff --git a/src/interfaces/ecpg/preproc/ecpg.trailer b/src/interfaces/ecpg/preproc/ecpg.trailer
index 342b7bc..fd35dfc 100644
--- a/src/interfaces/ecpg/preproc/ecpg.trailer
+++ b/src/interfaces/ecpg/preproc/ecpg.trailer
@@ -837,7 +837,12 @@ opt_signed: SQL_SIGNED
 variable_list: variable
 			{ $$ = $1; }
 		| variable_list ',' variable
-			{ $$ = cat_str(3, $1, mm_strdup(,), $3); }
+		{
+			if (actual_type[struct_level].type_enum == ECPGt_varchar)
+$$ = cat_str(3, $1, mm_strdup(;), $3);
+			else
+$$ = cat_str(3, $1, mm_strdup(,), $3);
+		}
 		;
 
 variable: opt_pointer ECPGColLabel opt_array_bounds opt_bit_field opt_initializer
commit b6d57b3fa709757769eb27083d7231602f2d806c
Author: Böszörményi Zoltán z...@cybertec.at
Date:   Wed Nov 20 10:33:40 2013 +0100

ECPG: Free the malloc()'ed variables in the test so it comes out
clean on Valgrind runs.

diff --git a/src/interfaces/ecpg/test/expected/preproc-outofscope.c b/src/interfaces/ecpg/test/expected/preproc-outofscope.c
index 125d7d8..2438911 100644
--- a/src/interfaces/ecpg/test/expected/preproc-outofscope.c
+++ b/src/interfaces/ecpg/test/expected/preproc-outofscope.c
@@ -347,28 +347,31 @@ if (sqlca.sqlcode  0) exit (1);}
 
 	close_cur1();
 
+	free(myvar);
+	free(mynullvar);
+
 	strcpy(msg, drop);
 	{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, drop table a1, ECPGt_EOIT, ECPGt_EORT);
-#line 115 outofscope.pgc
+#line 118 outofscope.pgc
 
 if (sqlca.sqlcode  0) exit (1);}
-#line 115 outofscope.pgc
+#line 118 outofscope.pgc
 
 
 	strcpy(msg, commit);
 	{ ECPGtrans(__LINE__, NULL, commit);
-#line 118 outofscope.pgc
+#line 121 outofscope.pgc
 
 if (sqlca.sqlcode  0) exit (1);}
-#line 118 outofscope.pgc
+#line 121 outofscope.pgc
 
 
 	strcpy(msg, disconnect);
 	{ ECPGdisconnect(__LINE__, CURRENT);
-#line 121 outofscope.pgc
+#line 124 outofscope.pgc
 
 if (sqlca.sqlcode  0) exit (1);}
-#line 121 outofscope.pgc
+#line 124 outofscope.pgc
 
 
 	return (0);
diff --git a/src/interfaces/ecpg/test/expected/preproc-outofscope.stderr b/src/interfaces/ecpg/test/expected/preproc-outofscope.stderr
index 91d3505..c7f8771 100644
--- a/src/interfaces/ecpg/test/expected/preproc-outofscope.stderr
+++ b/src/interfaces/ecpg/test/expected/preproc-outofscope.stderr
@@ -102,13 +102,13 @@
 [NO_PID]: sqlca: code: 0, state: 0
 [NO_PID]: ecpg_execute on line 58: OK: CLOSE CURSOR
 [NO_PID]: sqlca: code: 0, state: 0
-[NO_PID]: ecpg_execute on line 115: query: drop table a1; with 0 parameter(s) on connection regress1
+[NO_PID]: ecpg_execute on line 118: query: drop table a1; with 0 parameter(s) on connection regress1
 [NO_PID]: sqlca: code: 0, state: 0
-[NO_PID]: ecpg_execute on line 115: using PQexec
+[NO_PID]: ecpg_execute on line 118: using PQexec
 [NO_PID]: sqlca: code: 0, state: 0
-[NO_PID]: ecpg_execute on line 115: OK: DROP TABLE
+[NO_PID]: ecpg_execute on line

[HACKERS] Modify the DECLARE CURSOR command tag depending on the scrollable flag

2013-11-20 Thread Boszormenyi Zoltan

2013-11-20 14:41 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:15 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:01 keltezéssel, Noah Misch írta:

On Mon, Nov 11, 2013 at 10:17:54AM +0100, Boszormenyi Zoltan wrote:

The old contents of my GIT repository was removed so you need to
clone it fresh. https://github.com/zboszor/ecpg-readahead.git
I won't post the humongous patch again, since sending a 90KB
compressed file to everyone on the list is rude.

Patches of that weight show up on a regular basis.  I don't think it's rude.


OK, here it is.


...
Subsequent patches will come as reply to this email.


Attached is the patch that modified the command tag returned by
the DECLARE CURSOR command. It returns DECLARE SCROLL CURSOR
or DECLARE NO SCROLL CURSOR depending on the cursor's
scrollable flag that can be determined internally even if neither is
asked explicitly.

It is expected by the ECPG cursor readahead code.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

commit a691e262f562debd4b8991728fddd1e0895cf907
Author: Böszörményi Zoltán z...@cybertec.at
Date:   Wed Nov 20 10:50:31 2013 +0100

The backend knows whether the cursor is scrollable if neither SCROLL
nor NO SCROLL was specified. Inform the clients about this property
in the command tag: DECLARE SCROLL CURSOR or DECLARE NO SCROLL CURSOR.
The upcoming ECPG cursor handling code uses it. One contrib and some
ECPG regression tests have changed.

diff --git a/contrib/dblink/expected/dblink.out b/contrib/dblink/expected/dblink.out
index f237c43..d2b5d69 100644
--- a/contrib/dblink/expected/dblink.out
+++ b/contrib/dblink/expected/dblink.out
@@ -442,9 +442,9 @@ SELECT dblink_close('myconn','rmt_foo_cursor');
 
 -- this should succeed because we have an open transaction
 SELECT dblink_exec('myconn','DECLARE xact_test CURSOR FOR SELECT * FROM foo');
-  dblink_exec   
-
- DECLARE CURSOR
+  dblink_exec  
+---
+ DECLARE SCROLL CURSOR
 (1 row)
 
 -- commit remote transaction
@@ -477,9 +477,9 @@ SELECT dblink_close('myconn','rmt_foo_cursor2');
 
 -- this should succeed because we have an open transaction
 SELECT dblink_exec('myconn','DECLARE xact_test CURSOR FOR SELECT * FROM foo');
-  dblink_exec   
-
- DECLARE CURSOR
+  dblink_exec  
+---
+ DECLARE SCROLL CURSOR
 (1 row)
 
 -- this should commit the transaction
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c
index 5c3f42c..ef36d78 100644
--- a/src/backend/commands/portalcmds.c
+++ b/src/backend/commands/portalcmds.c
@@ -42,7 +42,8 @@
  */
 void
 PerformCursorOpen(PlannedStmt *stmt, ParamListInfo params,
-  const char *queryString, bool isTopLevel)
+  const char *queryString, bool isTopLevel,
+  bool *scrollable)
 {
 	DeclareCursorStmt *cstmt = (DeclareCursorStmt *) stmt-utilityStmt;
 	Portal		portal;
@@ -118,6 +119,8 @@ PerformCursorOpen(PlannedStmt *stmt, ParamListInfo params,
 			portal-cursorOptions |= CURSOR_OPT_NO_SCROLL;
 	}
 
+	*scrollable = !!(portal-cursorOptions  CURSOR_OPT_SCROLL);
+
 	/*
 	 * Start execution, inserting parameters if any.
 	 */
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 6a7bf0d..89665cc 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -505,11 +505,15 @@ standard_ProcessUtility(Node *parsetree,
 		case T_PlannedStmt:
 			{
 PlannedStmt *stmt = (PlannedStmt *) parsetree;
+bool		scrollable;
 
 if (stmt-utilityStmt == NULL ||
 	!IsA(stmt-utilityStmt, DeclareCursorStmt))
 	elog(ERROR, non-DECLARE CURSOR PlannedStmt passed to ProcessUtility);
-PerformCursorOpen(stmt, params, queryString, isTopLevel);
+PerformCursorOpen(stmt, params, queryString, isTopLevel, scrollable);
+if (completionTag)
+	sprintf(completionTag, DECLARE %s CURSOR,
+			   (scrollable ? SCROLL : NO SCROLL));
 			}
 			break;
 
diff --git a/src/include/commands/portalcmds.h b/src/include/commands/portalcmds.h
index b123bbd..8e756a8 100644
--- a/src/include/commands/portalcmds.h
+++ b/src/include/commands/portalcmds.h
@@ -19,7 +19,8 @@
 
 
 extern void PerformCursorOpen(PlannedStmt *stmt, ParamListInfo params,
-  const char *queryString, bool isTopLevel);
+  const char *queryString, bool isTopLevel,
+  bool *scrollable);
 
 extern void PerformPortalFetch(FetchStmt *stmt, DestReceiver *dest,
    char *completionTag);
diff --git a/src/interfaces/ecpg/test/expected/compat_informix-sqlda.stderr b/src/interfaces/ecpg/test/expected/compat_informix-sqlda.stderr
index f463d03..fc36a14 100644
--- a/src/interfaces/ecpg/test/expected/compat_informix-sqlda.stderr
+++ b/src/interfaces/ecpg/test/expected/compat_informix-sqlda.stderr
@@ -28,7 +28,7 @@
 [NO_PID

[HACKERS] ECPG infrastructure changes, part 2, was: Re: ECPG fixes

2013-11-20 Thread Boszormenyi Zoltan

2013-11-20 14:41 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:15 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:01 keltezéssel, Noah Misch írta:

On Mon, Nov 11, 2013 at 10:17:54AM +0100, Boszormenyi Zoltan wrote:

The old contents of my GIT repository was removed so you need to
clone it fresh. https://github.com/zboszor/ecpg-readahead.git
I won't post the humongous patch again, since sending a 90KB
compressed file to everyone on the list is rude.

Patches of that weight show up on a regular basis.  I don't think it's rude.


OK, here it is.


...
Subsequent patches will come as reply to this email.


ecpg_log() fixes after part 1 that produces a lot of regression test changes.
This patch is over 200K in itself so I send it separately and compressed.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



17.patch.gz
Description: Unix tar archive

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] ECPG infrastructure changes, part 3, was: Re: ECPG fixes

2013-11-20 Thread Boszormenyi Zoltan

2013-11-20 14:41 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:15 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:01 keltezéssel, Noah Misch írta:

On Mon, Nov 11, 2013 at 10:17:54AM +0100, Boszormenyi Zoltan wrote:

The old contents of my GIT repository was removed so you need to
clone it fresh. https://github.com/zboszor/ecpg-readahead.git
I won't post the humongous patch again, since sending a 90KB
compressed file to everyone on the list is rude.

Patches of that weight show up on a regular basis.  I don't think it's rude.


OK, here it is.


...
Subsequent patches will come as reply to this email.


Further ecpglib/execute.c changes.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

commit c901afd59894f49001b743982d38a51b23bac8e1
Author: Böszörményi Zoltán z...@cybertec.at
Date:   Wed Nov 20 11:05:34 2013 +0100

ECPG: Explicitly decouple the tuple index from the array index
in ecpg_get_data(). Document the function arguments.

diff --git a/src/interfaces/ecpg/ecpglib/data.c b/src/interfaces/ecpg/ecpglib/data.c
index 5f9a3d4..7f3c7cb 100644
--- a/src/interfaces/ecpg/ecpglib/data.c
+++ b/src/interfaces/ecpg/ecpglib/data.c
@@ -119,8 +119,35 @@ check_special_value(char *ptr, double *retval, char **endptr)
 	return false;
 }
 
+/*
+ * ecpg_get_data
+ *   Store one field data from PQgetvalue(results, act_tuple, act_field)
+ *   into a target variable. If the field is NULL, store the indication or
+ *   emit an error about the fact that there is no NULL indicator given.
+ * Parameters:
+ *   results: result set
+ *   act_tuple:   row index in the result set
+ *   act_field:   column index in the result set
+ *   var_index:   array index in the target variable
+ *   lineno:  line number in the ECPG source file for debugging
+ *   type:type of target variable
+ *   ind_type:type of NULL indicator variable
+ *   var: target variable
+ *   ind: NULL indicator variable
+ *   varcharsize: size of the variable if it's varchar
+ *   offset:  size of the target variable
+ *(used for indexing in an array)
+ *   ind_offset:  size of the NULL indicator variable
+ *(used for indexing in an array)
+ *   isarray: array type
+ *   compat:  native PostgreSQL or Informix compatibility mode
+ *   force_indicator:
+ *if Informix compatibility mode is set and no NULL indicator
+ *is given, provide a way to indicate NULL value in the
+ *target variable itself
+ */
 bool
-ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
+ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int var_index, int lineno,
 			  enum ECPGttype type, enum ECPGttype ind_type,
 			  char *var, char *ind, long varcharsize, long offset,
 			  long ind_offset, enum ARRAY_TYPE isarray, enum COMPAT_MODE compat, bool force_indicator)
@@ -167,20 +194,20 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
 	{
 		case ECPGt_short:
 		case ECPGt_unsigned_short:
-			*((short *) (ind + ind_offset * act_tuple)) = value_for_indicator;
+			*((short *) (ind + ind_offset * var_index)) = value_for_indicator;
 			break;
 		case ECPGt_int:
 		case ECPGt_unsigned_int:
-			*((int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
+			*((int *) (ind + ind_offset * var_index)) = value_for_indicator;
 			break;
 		case ECPGt_long:
 		case ECPGt_unsigned_long:
-			*((long *) (ind + ind_offset * act_tuple)) = value_for_indicator;
+			*((long *) (ind + ind_offset * var_index)) = value_for_indicator;
 			break;
 #ifdef HAVE_LONG_LONG_INT
 		case ECPGt_long_long:
 		case ECPGt_unsigned_long_long:
-			*((long long int *) (ind + ind_offset * act_tuple)) = value_for_indicator;
+			*((long long int *) (ind + ind_offset * var_index)) = value_for_indicator;
 			break;
 #endif   /* HAVE_LONG_LONG_INT */
 		case ECPGt_NO_INDICATOR:
@@ -192,7 +219,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
 	 * Informix has an additional way to specify NULLs note
 	 * that this uses special values to denote NULL
 	 */
-	ECPGset_noind_null(type, var + offset * act_tuple);
+	ECPGset_noind_null(type, var + offset * var_index);
 }
 else
 {
@@ -243,10 +270,10 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
 		if (binary)
 		{
 			if (varcharsize == 0 || varcharsize * offset = size)
-memcpy(var + offset * act_tuple, pval, size);
+memcpy(var + offset * var_index, pval, size);
 			else
 			{
-memcpy(var + offset * act_tuple, pval, varcharsize * offset);
+memcpy(var + offset * var_index, pval, varcharsize * offset);
 
 if (varcharsize * offset  size)
 {
@@ -255,20

[HACKERS] ECPG infrastructure changes, part 4, was: Re: ECPG fixes

2013-11-20 Thread Boszormenyi Zoltan

2013-11-20 14:41 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:15 keltezéssel, Boszormenyi Zoltan írta:

2013-11-12 07:01 keltezéssel, Noah Misch írta:

On Mon, Nov 11, 2013 at 10:17:54AM +0100, Boszormenyi Zoltan wrote:

The old contents of my GIT repository was removed so you need to
clone it fresh. https://github.com/zboszor/ecpg-readahead.git
I won't post the humongous patch again, since sending a 90KB
compressed file to everyone on the list is rude.

Patches of that weight show up on a regular basis.  I don't think it's rude.


OK, here it is.


...
Subsequent patches will come as reply to this email.


This is another, semi independent subfeature of ECPG readahead.
It's about 150K by itself, so I send it compressed.

The purpose of this patch is to track (sub-)transactions and cursors
in ecpglib to reduce network turnaround and speed up the application
in certain cases. E.g. cursors are discarded upon ROLLBACK TO
SAVEPOINT and ecpglib needs to know about it. When an unknown
savepoint or cursor name is sent, ecpglib would not send the command
to the server in an open transaction after this patch. Instead, it flips
a client-side error flag and returns the same error the backend
would in this case.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



23.patch.gz
Description: Unix tar archive

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] ECPG FETCH readahead

2013-11-11 Thread Boszormenyi Zoltan

2013-10-11 00:16 keltezéssel, Alvaro Herrera írta:

Boszormenyi Zoltan escribió:

2013-09-10 03:04 keltezéssel, Peter Eisentraut írta:

You need to update the dblink regression tests.

Done.

Dude, this is an humongous patch.  I was shocked by it initially, but on
further reading, I observed that it's only a huge patch which also does
some mechanical changes to test output.  I think it'd be better to split
the part that's responsible for the changed lines in test output
mentioning ecpg_process_output.  That should be a reasonably small
patch which changes ecpg_execute slightly and adds the new function, is
followed by the enormous resulting mechanical changes in test output.
It should be possible to commit that relatively quickly.  Then there's
the rest of the patch, which would adds a huge pile of new code.

I think there are some very minor changes to backend code as well --
would it make sense to post that as a separate piece?


I had to rebase the patch against current (today morning's) GIT, since
there were a few changes against ECPG in the meantime.

The old contents of my GIT repository was removed so you need to
clone it fresh. https://github.com/zboszor/ecpg-readahead.git
I won't post the humongous patch again, since sending a 90KB
compressed file to everyone on the list is rude. You can pull
the commits individually from the above repository. For the same
reason, I won't add the DECLARE CURSOR command tag change
separately since this is also part of this big feature.

I have reordered some patches, like some independent bug fixes
against the ECPG parser and regression tests. The backend change
is also added early.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Commitfest II CLosed

2013-10-21 Thread Boszormenyi Zoltan

2013-10-21 17:11 keltezéssel, Robert Haas írta:

On Mon, Oct 21, 2013 at 9:18 AM, Andres Freund and...@2ndquadrant.com wrote:

On 2013-10-21 09:15:36 -0400, Peter Eisentraut wrote:

On 10/21/13 1:31 AM, Andres Freund wrote:

The point of the CF is exactly that all
patches get at least one good round of review. Moving unreviewed patches
to the next CF will let them just suffer the same fate there.

What is the alternative?

I am not 100% sure, but what's the point of the CF if we're not actually
reviewing patches that wouldn't get review without it? So I guess it's
not starting the next one before we've finished - which we obviously
haven't in this case - the last one.

Yeah.  There were a huge number of patches in this CommitFest that sat
around in the waiting on author state for hugely long periods of time.
  One of the critical functions of the CommitFest manager(s) IMV is to
make sure that patches that are in that state get pushed to Returned
with Feedback so that it's more obvious which things are still alive
and kicking.  That really wasn't done until about a week before the
end of the CommitFest, when I stepped in and did some of it.  But that
really needs to be more of an ongoing process.

Supposedly, we have a policy that for each patch you submit, you ought
to review a patch.  That right there ought to provide enough reviewers
for all the patches, but clearly it didn't.  And I'm pretty sure that
some people (like me) looked at a lot MORE patches than they
themselves submitted.  I think auditing who is not contributing in
that area and finding tactful ways to encourage them to contribute
would be a very useful service to the project.


I wanted to get to this point, too.

I hoped that reviewing 4 patches in this CF (UNNEST, Extension templates,
DISCARD SEQUENCES, and extended RETURNING syntax) gets my huge patch reviewed.

I even provided a repo @github where it was broken up into pieces that can be 
sanely reviewed.
It still wasn't enough. Even Michael Meskes (ECPG is his pet project) and the 
guy @Fujitsu
who contacted me privately and expressed interest in this patch didn't chime in.
As a social experiment, the CF looks like a clear failure from this seat of 
mine. (Sorry.)



Finally, I think we need to have some discussion of the patches that
are ready for committer but got punted, and see if we can figure out
whether any committer has plans to look at them.  Those patches are:

Extension Templates - I think Peter Eisentraut commented on this one
at some stage, but I'm not sure if he's planning to work further on
it.
UNNEST with multiple args, and TABLE with multiple functions - Heikki
did some work on this, maybe he's planning to commit it?
Numeric Aggregates Performance Improvement - I looked at this one
previously so should probably look it over again.
Statistics collection for CLUSTER command - Noah recommended rejecting
this on performance grounds.  Maybe we should do that.
simple date time constructors - Alvaro previously looked at this, but
I don't know whether he plans to work on it further.
simple LO API - no committer interest to my knowledge
Bugfix for timeout in LDAP connection parameter resolution - I think
Peter Eisentraut is planning to commit this




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Commitfest II CLosed

2013-10-21 Thread Boszormenyi Zoltan

2013-10-21 18:25 keltezéssel, Stephen Frost írta:

Zoltan,

* Boszormenyi Zoltan (z...@cybertec.at) wrote:

I even provided a repo @github where it was broken up into pieces that can be 
sanely reviewed.

You also gave the first person looking at the patch a hard time about
asking for it to be broken up; unnecessairly, imv.


Sorry if it felt that way.  I gave the commit IDs about the points he brought 
up.


   Thanks for breaking
it up and for doing patch review of other patches- it does help the
project move forward.  Try to be understanding when someone asks a
question that's already been answered; we're all quite busy and may
forget or miss things.

I don't know if Alvaro will have time to look into this or if he perhaps
already has, but I had noticed this patch earlier and it was one of the
ones I had hoped to take a look at, as I've been in the ECPG bits due to
the work with Coverity that I've been doing.  I'll try and provide
feedback later this week/weekend on it.

Thanks,

Stephen



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Commitfest II CLosed

2013-10-21 Thread Boszormenyi Zoltan

2013-10-21 19:10 keltezéssel, Alvaro Herrera írta:

Boszormenyi Zoltan escribió:


I hoped that reviewing 4 patches in this CF (UNNEST, Extension templates,
DISCARD SEQUENCES, and extended RETURNING syntax) gets my huge patch reviewed.

I'm still on the hook for parts of this one (and also for Pavel's date
constructors stuff).


Thank you very much.


I won't touch the ones that modify the core of
ecpg, but I hope I hope I will be able to look at the other ones to ease
work for Michael.


I hope he has time for this patch soon. When this patch was brought up
last time, he expressed interest.


I spent the last two weeks moving to another city,
which was pretty exhausting, so I wasn't able to get as much done as I
hoped.  It's finally done now and today I got a stable network
connection in the new place.


I wish you the best with your new place and friendly neighbours! :-)

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Commitfest II CLosed

2013-10-20 Thread Boszormenyi Zoltan

Hi,

2013-10-19 17:20 keltezéssel, David Fetter írta:

Thanks very much to Mike Blackwell and Craig Kerstiens for their
persistence through what most people would consider a tedious and
thankless task.  Thanks also to the patch submitters, reviewers and
other participants.

That the formal commitfest is over does not mean that your patch won't
get reviewed or committed until November.  What it does mean is that
people will be setting patch review as a lower priority, frequently so
they can live their lives, work on new stuff, do their day jobs...

We got 20 patches, many quite significant, committed this time.
Kudos!

Cheers,
David.


what will happen to patches left in pending state in the 2013-09 CF?

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] ECPG FETCH readahead

2013-10-13 Thread Boszormenyi Zoltan

2013-10-11 00:16 keltezéssel, Alvaro Herrera írta:

Boszormenyi Zoltan escribió:

2013-09-10 03:04 keltezéssel, Peter Eisentraut írta:

You need to update the dblink regression tests.

Done.

Dude, this is an humongous patch.


You *know* that the patch is available in pieces at 
https://github.com/zboszor/ecpg-readahead
right? You must have read the new initial announcement at
http://archives.postgresql.org/message-id/520f4b90.2010...@cybertec.at

You can review and merge them one by one.
The transformation of ecpg_execute() and friends starts at
2d04ff83984c63c34e55175317e3e431eb58e00c


   I was shocked by it initially, but on
further reading, I observed that it's only a huge patch which also does
some mechanical changes to test output.  I think it'd be better to split
the part that's responsible for the changed lines in test output
mentioning ecpg_process_output.


It's 1e0747576e96aae3ec8c60c46baea130aaf8916e in the above repository.

Also, another huge regression test patch is where the cursor readahead
is enabled unconditionally: 27e43069082b29cb6fa4d3414e6484ec7fb80cbe


   That should be a reasonably small
patch which changes ecpg_execute slightly and adds the new function, is
followed by the enormous resulting mechanical changes in test output.
It should be possible to commit that relatively quickly.  Then there's
the rest of the patch, which would adds a huge pile of new code.

I think there are some very minor changes to backend code as well --
would it make sense to post that as a separate piece?


It's 2ad207e6371a33d6a985c76ac066dd51ed5681cb
Also, cd881f0363b1aff1508cfa347e8df6b4981f0ee7 to fix the dblink regression 
test.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] WHERE CURRENT OF behaviour is not what's documented

2013-09-18 Thread Boszormenyi Zoltan

Hi,

I have experimented with cursors a little and found that the part about FOR SHARE/FOR 
UPDATE in


http://www.postgresql.org/docs/9.2/interactive/sql-declare.html

i.e. the sensitive cursor is not what actually happens. BTW, 9.3 has the same contents 
for the same page.



If the cursor's query includes FOR UPDATE or FOR SHARE, then returned rows are locked at 
the time they are first fetched, in the same way as for a regular SELECT 
http://www.postgresql.org/docs/9.3/interactive/sql-select.html command with these 
options. In addition, the returned rows will be the most up-to-date versions; therefore 
these options provide the equivalent of what the SQL standard calls a sensitive cursor. 
(Specifying INSENSITIVE together with FOR UPDATE or FOR SHARE is an error.)



The statement that the most up-to-date versions of the rows are returned
doesn't reflect the reality anymore:

$ psql
psql (9.2.4)
Type help for help.

zozo= create table xxx (id serial primary key, t text);
NOTICE:  CREATE TABLE will create implicit sequence xxx_id_seq for serial column 
xxx.id
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index xxx_pkey for table 
xxx
CREATE TABLE
zozo= insert into xxx (t) values ('a'), ('b'), ('c');
INSERT 0 3
zozo= begin;
BEGIN
zozo= declare mycur cursor for select * from xxx for update;
DECLARE CURSOR
zozo= fetch all from mycur;
 id | t
+---
  1 | a
  2 | b
  3 | c
(3 rows)

zozo= move absolute 0 in mycur;
MOVE 0
zozo= fetch from mycur;
 id | t
+---
  1 | a
(1 row)

zozo= update xxx set t = t || '_x' where current of mycur;
UPDATE 1
zozo= move absolute 0 in mycur;
MOVE 0
zozo= fetch all from mycur;
 id | t
+---
  2 | b
  3 | c
(2 rows)

What happened to the most up-to-date row of id == 1?

zozo= select * from xxx where id = 1;
 id |  t
+-
  1 | a_x
(1 row)

The same behaviour is experienced under 9.2.4 and 9.3.0.

As a side note, I couldn't test 8.4.17, 9.0.13 and 9.1.9 under Fedora 19,
because initdb fails for all 3 versions. I am bitten by the same as what's
described here: 
http://www.postgresql.org/message-id/14242.1365200...@sss.pgh.pa.us

It the above cursor behaviour is the accepted/expected one?

Since SCROLL (with or without INSENSITIVE) cannot be specified together
with FOR UPDATE/FOR SHARE, I know the MOVE ABSOLUTE 0 is on the
verge of being invalid in this case.

But in any case, either the documentation should tell that the UPDATEd
rows will be missing from a reset executor run or MOVE ABSOLUTE
with a value smaller than portal-portalPos should also be refused
just like MOVE BACKWARD.

As another side note, portal-portalPos mentions it can overflow,
so I suggest using int64 explicitly, so it's ensured that 32-bit systems
get the same overflow behaviour as 64-bit ones. Or (the horror, the horror!) 
int128_t.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] WHERE CURRENT OF behaviour is not what's documented

2013-09-18 Thread Boszormenyi Zoltan

2013-09-18 14:27 keltezéssel, Andres Freund írta:

On 2013-09-18 14:23:19 +0200, Boszormenyi Zoltan wrote:

Hi,

I have experimented with cursors a little and found that the part about FOR
SHARE/FOR UPDATE in

http://www.postgresql.org/docs/9.2/interactive/sql-declare.html

i.e. the sensitive cursor is not what actually happens. BTW, 9.3 has the
same contents for the same page.


If the cursor's query includes FOR UPDATE or FOR SHARE, then returned rows
are locked at the time they are first fetched, in the same way as for a
regular SELECT
http://www.postgresql.org/docs/9.3/interactive/sql-select.html command
with these options. In addition, the returned rows will be the most
up-to-date versions; therefore these options provide the equivalent of what
the SQL standard calls a sensitive cursor. (Specifying INSENSITIVE
together with FOR UPDATE or FOR SHARE is an error.)


The statement that the most up-to-date versions of the rows are returned
doesn't reflect the reality anymore:

I think it's not referring to the behaviour inside a single session but
across multiple sessions. I.e. when we follow the ctid chain of a tuple
updated in a concurrent session.


But the documentation doesn't spell it out. Perhaps a little too terse.

Quoting the SQL2011 draft, 4.33.2 Operations on and using cursors, page 112:

If a cursor is open, and the SQL-transaction in which the cursor was opened makes a 
significant change to
SQL-data, then whether that change is visible through that cursor before it is closed is 
determined as follows:

— If the cursor is insensitive, then significant changes are not visible.
— If the cursor is sensitive, then significant changes are visible.
— If the cursor is asensitive, then the visibility of significant changes is 
implementation-dependent.


SQL2003 has the same wording in 4.32.2 Operations on and using cursors
on page 96.

So, a SENSITIVE cursor shows significant changes (I guess a modified
row counts as one) and they should be shown in the _same_ transaction
where the cursor was opened. If anything, the PostgreSQL cursor
implementation for FOR SHARE/FOR UPDATE is asensitive.

Also, 14.10 update statement: positioned, paragraph 14) in General Rules
in SQL2003 (page 848) or 15.6 Effect of a positioned update, paragraph 16)
in SQL2011 draft (page 996) says the new row replaces the old row
*in the cursor*, not just in the table. Quote:


Let R1 be the candidate new row and let R be the current row of CR.
...
The current row R of CR is replaced by R1.


Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] UNNEST with multiple args, and TABLE with multiple funcs

2013-09-16 Thread Boszormenyi Zoltan

2013-09-13 21:03 keltezéssel, Andrew Gierth írta:

Latest version of patch, incorporating regression tests and docs, and
fixing the operator issue previously raised.


It looks good. I think it's ready for a committer.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Proposal: UPDATE/DELETE ... WHERE OFFSET n OF cursor_name, was: Re: New ECPG idea, was: Re: [HACKERS] ECPG FETCH readahead

2013-09-16 Thread Boszormenyi Zoltan

Hi,

2013-08-17 13:02 keltezéssel, Boszormenyi Zoltan írta:
[snip, discussion of WHERE CURRENT OF in the ECPG client lib]

I had a second thought about it and the client side caching and
parser behind the application's back seems to be an overkill.

Instead, I propose a different solution, which is a logical extension of
FETCH { FORWARD | BACKWARD } N, which is a PostgreSQL extension.

The proposed solution would be:

UPDATE / DELETE ... WHERE OFFSET SignedIconst OF cursor_name

I imagine that FETCH would keep the array of TIDs/ItemPointerDatas
of the last FETCH statement.

The argument to OFFSET would be mostly in negative terms,
with 0 being equivalent of WHERE CURRENT OF.

E.g.:

FETCH 2 FROM mycur; -- fetches two rows
UPDATE mytab SET ... WHERE OFFSET -1 OF mycur; -- updates the first row
UPDATE mytab SET ... WHERE OFFSET 0 OF mycur; -- updates current row

or

FETCH 3 FROM mycur; -- fetches two rows, reaches end of the cursor
UPDATE mytab SET ... WHERE OFFSET -2 OF mycur; -- updates the first row
UPDATE mytab SET ... WHERE OFFSET -1 OF mycur; -- updates the second row
UPDATE mytab SET ... WHERE OFFSET 0 OF mycur; -- throws an error like WHERE 
CURRENT OF

or

FETCH 3 FROM mycur; -- fetches two rows, reaches end of the cursor
MOVE BACKWARD 2 IN mycur;
UPDATE mytab SET ... WHERE OFFSET 0 OF mycur; -- updates the first row (now 
current)
UPDATE mytab SET ... WHERE OFFSET 1 OF mycur; -- updates the second row

The cached array can be kept valid until the next FETCH statement,
even if  moves out of the interval of the array, except in case the
application changes the sign of the cursor position, e.g. previously it used
MOVE ABSOLUTE with positive numbers and suddenly it switches to
backward scanning with MOVE ABSOLUTE negative number or vice-versa.

This would solve the only source of slowdown in the client side cursor caching
in ECPG present in my current ECPG cursor readahead patch, there would be
no more MOVE + UPDATE/DELETE WHERE CURRENT OF. On the other hand,
exploiting this proposed feature in ECPG would make it incompatible with older
servers unless it detects the server version it connects to and uses the current
method.

Comments?

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] UNNEST with multiple args, and TABLE with multiple funcs

2013-08-27 Thread Boszormenyi Zoltan

2013-08-27 01:24 keltezéssel, Andrew Gierth írta:

Latest version of patch. This should be it as far as code goes; there
may be some more regression test work, and a doc patch will be
forthcoming.

This version supports, in addition to the previous stuff:

[snip]


In my limited testing, it works well, and the patch looks good.

When adding regression tests, can you please add intentional
syntax error cases to exercise all the new ereport()s?

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Extension Templates S03E11

2013-08-27 Thread Boszormenyi Zoltan

2013-08-27 18:09 keltezéssel, Dimitri Fontaine írta:

Hi,

Boszormenyi Zoltan z...@cybertec.at writes:

Here's a review for this patch.

Thanks for that review Zoltan!


You're welcome.


I would like to see the control parameters documented in allcaps
in CREATE EXTENSION TEMPLATE. Then ALTER EXTENSION
TEMPLATE should reference the CREATE instead of the longer
text in xref linkend=extend-extensions. This xref can still
be there for reference in all three of CREATE/ALTER/DROP
EXTENSION TEMPLATE.

I didn't follow exactly your proposal here because I didn't want to have
to maintain the control parameter description list in two different
places. I've still added a detailed list with references and details and
more importantly with coverage of e.g. NORELOCATABLE which is not
covered in the referenced material.


It looks better. Now that the lowercase keywords are expected
by the eye in the referenced text, they will be much easier to find.
Thanks.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] GSOC13 proposal - extend RETURNING syntax

2013-08-21 Thread Boszormenyi Zoltan

Hi,

2013-08-20 21:06 keltezéssel, Karol Trzcionka írta:

W dniu 20.08.2013 20:55, Boszormenyi Zoltan pisze:

Here's a new one, for v7:

setrefs.c: In function ‘set_plan_refs’:
setrefs.c:2001:26: warning: ‘before_index’ may be used uninitialized in this function 
[-Wmaybe-uninitialized]

  bind_returning_variables(rlist, before_index, after_index);
  ^
setrefs.c:1957:21: note: ‘before_index’ was declared here
  int after_index=0, before_index;
 ^

Right, my mistake. Sorry and thanks. Fixed.
Regards,
Karol Trzcionka


With this fixed, a more complete review:

* Is the patch in a patch format which has context? (eg: context diff format)

Yes.

* Does it apply cleanly to the current git master?

Yes.

* Does it include reasonable tests, necessary doc patches, etc?

There is a new regression test (returning_before_after.sql) covering
this feature. However, I think it should be added to the group
where returning.sql resides currently. There is a value in running it
in parallel to other tests. Sometimes a subtle bug is uncovered
because of this and your v2 patch fixed such a bug already.

doc/src/sgml/ref/update.sgml describes this feature.

doc/src/sgml/dml.sgml should also be touched to cover this feature.

* Does the patch actually implement what it's supposed to do?

Yes.

* Do we want that?

Yes.

* Do we already have it?

No.

* Does it follow SQL spec, or the community-agreed behavior?

RETURNING is a PostgreSQL extension, so the SQL-spec part
of the question isn't applicable.

It implements the community-agreed behaviour, according to
the new regression test coverage.

* Does it include pg_dump support (if applicable)?

n/a

* Are there dangers?

I don't think so.

* Have all the bases been covered?

It seems so. I have also tried mixing before/after columns in
different orders and the query didn't fail:

zozo=# create table t1 (id serial primary key, i1 int4, i2 int4, t1 text, t2 
text);
CREATE TABLE
zozo=# insert into t1 (i1, i2, t1, t2) values (1, 1, 'a', 'a');
INSERT 0 1
zozo=# insert into t1 (i1, i2, t1, t2) values (2, 2, 'b', 'b');
INSERT 0 1
zozo=# insert into t1 (i1, i2, t1, t2) values (3, 3, 'c', 'c');
INSERT 0 1
zozo=# select * from t1;
 id | i1 | i2 | t1 | t2
++++
  1 |  1 |  1 | a  | a
  2 |  2 |  2 | b  | b
  3 |  3 |  3 | c  | c
(3 rows)

zozo=# begin;
BEGIN
zozo=# update t1 set i2 = i2*2, t2 = t2 || 'x2' where id = 2 returning before.i1, 
after.i1, before.i2, after.i2, before.t1, after.t1, before.t2, after.t2;

 i1 | i1 | i2 | i2 | t1 | t1 | t2 | t2
+++++++-
  2 |  2 |  2 |  4 | b  | b  | b  | bx2
(1 row)

UPDATE 1
zozo=# update t1 set i1 = i1 * 3, i2 = i2*2, t1 = t1 || 'x3', t2 = t2 || 'x2' where id = 3 
returning before.i1, before.i2, after.i1, after.i2, before.t1, before.t2, after.t1, 
after.t2; i1 | i2 | i1 | i2 | t1 | t2 | t1  | t2

++++++-+-
  3 |  3 |  9 |  6 | c  | c  | cx3 | cx2
(1 row)

UPDATE 1



* Does the feature work as advertised?

Yes.

* Are there corner cases the author has failed to consider?

I don't know.

* Are there any assertion failures or crashes?

No.

* Does the patch slow down simple tests?

No.

* If it claims to improve performance, does it?

n/a

* Does it slow down other things?

No.

* Does it follow the project coding guidelines?

Mostly.

In the src/test/regress/parallel_schedule contains an extra
new line at the end, it shouldn't.

In b/src/backend/optimizer/plan/setrefs.c:

+static void bind_returning_variables(List *rlist, int bef, int aft);

but later it becomes not public:

+ */
+void bind_returning_variables(List *rlist, int bef, int aft)
+{

Strange, but GCC 4.8.1 -Wall doesn't catch it. But the forward
declaration is not needed, the function is called only from
later functions.

Similar for parse_clause.c:

+extern void addAliases(ParseState *pstate);

+void addAliases(ParseState *pstate)

This external declaration is not needed since it is already
in src/include/parser/parse_clause.h

In setrefs.c, bind_returning_variables() I would also rename
the function arguments, so before and after are spelled out.
These are not C keywords.

Some assignments, like:

+   var=(Var*)tle;
and
+   int index_rel=1;

in setrefs.c need spaces.

if() statements need a space before the ( and not after.

Add spaces in the {} list in addAliases():
+   char*aliases[] = {before,after};
like this: { before, after }

Spaces are needed here, too:
+   for(i=0 ; inoal; i++)

This noal should be naliases or n_aliases if you really want
a variable. I would simply use the constant 2 for the two for()
loops in addAliases() instead, its purpose is obvious enough.

In setrefs.c, bind_returning_variables():
+   Var *var = NULL;
+   foreach(temp, rlist){
Add an empty line after the declaration block.


* Are there portability issues?

No.

* Will it work on Windows/BSD etc?

Yes.

* Are the comments sufficient

Re: [HACKERS] GSOC13 proposal - extend RETURNING syntax

2013-08-21 Thread Boszormenyi Zoltan

2013-08-21 19:17 keltezéssel, Boszormenyi Zoltan írta:

Hi,

2013-08-20 21:06 keltezéssel, Karol Trzcionka írta:

W dniu 20.08.2013 20:55, Boszormenyi Zoltan pisze:

Here's a new one, for v7:

setrefs.c: In function ‘set_plan_refs’:
setrefs.c:2001:26: warning: ‘before_index’ may be used uninitialized in this function 
[-Wmaybe-uninitialized]

  bind_returning_variables(rlist, before_index, after_index);
  ^
setrefs.c:1957:21: note: ‘before_index’ was declared here
  int after_index=0, before_index;
 ^

Right, my mistake. Sorry and thanks. Fixed.
Regards,
Karol Trzcionka


With this fixed, a more complete review:

* Is the patch in a patch format which has context? (eg: context diff format)

Yes.

* Does it apply cleanly to the current git master?

Yes.

* Does it include reasonable tests, necessary doc patches, etc?

There is a new regression test (returning_before_after.sql) covering
this feature. However, I think it should be added to the group
where returning.sql resides currently. There is a value in running it
in parallel to other tests. Sometimes a subtle bug is uncovered
because of this and your v2 patch fixed such a bug already.

doc/src/sgml/ref/update.sgml describes this feature.

doc/src/sgml/dml.sgml should also be touched to cover this feature.

* Does the patch actually implement what it's supposed to do?

Yes.

* Do we want that?

Yes.

* Do we already have it?

No.

* Does it follow SQL spec, or the community-agreed behavior?

RETURNING is a PostgreSQL extension, so the SQL-spec part
of the question isn't applicable.

It implements the community-agreed behaviour, according to
the new regression test coverage.

* Does it include pg_dump support (if applicable)?

n/a

* Are there dangers?

I don't think so.

* Have all the bases been covered?

It seems so. I have also tried mixing before/after columns in
different orders and the query didn't fail:

zozo=# create table t1 (id serial primary key, i1 int4, i2 int4, t1 text, t2 
text);
CREATE TABLE
zozo=# insert into t1 (i1, i2, t1, t2) values (1, 1, 'a', 'a');
INSERT 0 1
zozo=# insert into t1 (i1, i2, t1, t2) values (2, 2, 'b', 'b');
INSERT 0 1
zozo=# insert into t1 (i1, i2, t1, t2) values (3, 3, 'c', 'c');
INSERT 0 1
zozo=# select * from t1;
 id | i1 | i2 | t1 | t2
++++
  1 |  1 |  1 | a  | a
  2 |  2 |  2 | b  | b
  3 |  3 |  3 | c  | c
(3 rows)

zozo=# begin;
BEGIN
zozo=# update t1 set i2 = i2*2, t2 = t2 || 'x2' where id = 2 returning before.i1, 
after.i1, before.i2, after.i2, before.t1, after.t1, before.t2, after.t2;

 i1 | i1 | i2 | i2 | t1 | t1 | t2 | t2
+++++++-
  2 |  2 |  2 |  4 | b  | b  | b  | bx2
(1 row)

UPDATE 1
zozo=# update t1 set i1 = i1 * 3, i2 = i2*2, t1 = t1 || 'x3', t2 = t2 || 'x2' where id = 
3 returning before.i1, before.i2, after.i1, after.i2, before.t1, before.t2, after.t1, 
after.t2; i1 | i2 | i1 | i2 | t1 | t2 | t1  | t2

++++++-+-
  3 |  3 |  9 |  6 | c  | c  | cx3 | cx2
(1 row)

UPDATE 1



* Does the feature work as advertised?

Yes.

* Are there corner cases the author has failed to consider?

I don't know.

* Are there any assertion failures or crashes?

No.

* Does the patch slow down simple tests?

No.

* If it claims to improve performance, does it?

n/a

* Does it slow down other things?

No.

* Does it follow the project coding guidelines?

Mostly.

In the src/test/regress/parallel_schedule contains an extra
new line at the end, it shouldn't.

In b/src/backend/optimizer/plan/setrefs.c:

+static void bind_returning_variables(List *rlist, int bef, int aft);

but later it becomes not public:

+ */
+void bind_returning_variables(List *rlist, int bef, int aft)
+{

Strange, but GCC 4.8.1 -Wall doesn't catch it. But the forward
declaration is not needed, the function is called only from
later functions.

Similar for parse_clause.c:

+extern void addAliases(ParseState *pstate);

+void addAliases(ParseState *pstate)

This external declaration is not needed since it is already
in src/include/parser/parse_clause.h

In setrefs.c, bind_returning_variables() I would also rename
the function arguments, so before and after are spelled out.
These are not C keywords.

Some assignments, like:

+   var=(Var*)tle;
and
+   int index_rel=1;

in setrefs.c need spaces.

if() statements need a space before the ( and not after.

Add spaces in the {} list in addAliases():
+   char*aliases[] = {before,after};
like this: { before, after }

Spaces are needed here, too:
+   for(i=0 ; inoal; i++)

This noal should be naliases or n_aliases if you really want
a variable. I would simply use the constant 2 for the two for()
loops in addAliases() instead, its purpose is obvious enough.

In setrefs.c, bind_returning_variables():
+   Var *var = NULL;
+   foreach(temp, rlist){
Add an empty line after the declaration block.


* Are there portability issues?

No.

* Will it work

Re: [HACKERS] GSOC13 proposal - extend RETURNING syntax

2013-08-21 Thread Boszormenyi Zoltan

2013-08-21 20:00 keltezéssel, Boszormenyi Zoltan írta:

2013-08-21 19:17 keltezéssel, Boszormenyi Zoltan írta:

Hi,

2013-08-20 21:06 keltezéssel, Karol Trzcionka írta:

W dniu 20.08.2013 20:55, Boszormenyi Zoltan pisze:

Here's a new one, for v7:

setrefs.c: In function ‘set_plan_refs’:
setrefs.c:2001:26: warning: ‘before_index’ may be used uninitialized in this function 
[-Wmaybe-uninitialized]

  bind_returning_variables(rlist, before_index, after_index);
  ^
setrefs.c:1957:21: note: ‘before_index’ was declared here
  int after_index=0, before_index;
 ^

Right, my mistake. Sorry and thanks. Fixed.
Regards,
Karol Trzcionka


With this fixed, a more complete review:

* Is the patch in a patch format which has context? (eg: context diff format)

Yes.

* Does it apply cleanly to the current git master?

Yes.

* Does it include reasonable tests, necessary doc patches, etc?

There is a new regression test (returning_before_after.sql) covering
this feature. However, I think it should be added to the group
where returning.sql resides currently. There is a value in running it
in parallel to other tests. Sometimes a subtle bug is uncovered
because of this and your v2 patch fixed such a bug already.

doc/src/sgml/ref/update.sgml describes this feature.

doc/src/sgml/dml.sgml should also be touched to cover this feature.

* Does the patch actually implement what it's supposed to do?

Yes.

* Do we want that?

Yes.

* Do we already have it?

No.

* Does it follow SQL spec, or the community-agreed behavior?

RETURNING is a PostgreSQL extension, so the SQL-spec part
of the question isn't applicable.

It implements the community-agreed behaviour, according to
the new regression test coverage.

* Does it include pg_dump support (if applicable)?

n/a

* Are there dangers?

I don't think so.

* Have all the bases been covered?

It seems so. I have also tried mixing before/after columns in
different orders and the query didn't fail:

zozo=# create table t1 (id serial primary key, i1 int4, i2 int4, t1 text, t2 
text);
CREATE TABLE
zozo=# insert into t1 (i1, i2, t1, t2) values (1, 1, 'a', 'a');
INSERT 0 1
zozo=# insert into t1 (i1, i2, t1, t2) values (2, 2, 'b', 'b');
INSERT 0 1
zozo=# insert into t1 (i1, i2, t1, t2) values (3, 3, 'c', 'c');
INSERT 0 1
zozo=# select * from t1;
 id | i1 | i2 | t1 | t2
++++
  1 |  1 |  1 | a  | a
  2 |  2 |  2 | b  | b
  3 |  3 |  3 | c  | c
(3 rows)

zozo=# begin;
BEGIN
zozo=# update t1 set i2 = i2*2, t2 = t2 || 'x2' where id = 2 returning before.i1, 
after.i1, before.i2, after.i2, before.t1, after.t1, before.t2, after.t2;

 i1 | i1 | i2 | i2 | t1 | t1 | t2 | t2
+++++++-
  2 |  2 |  2 |  4 | b  | b  | b  | bx2
(1 row)

UPDATE 1
zozo=# update t1 set i1 = i1 * 3, i2 = i2*2, t1 = t1 || 'x3', t2 = t2 || 'x2' where id 
= 3 returning before.i1, before.i2, after.i1, after.i2, before.t1, before.t2, after.t1, 
after.t2; i1 | i2 | i1 | i2 | t1 | t2 | t1  | t2

++++++-+-
  3 |  3 |  9 |  6 | c  | c  | cx3 | cx2
(1 row)

UPDATE 1



* Does the feature work as advertised?

Yes.

* Are there corner cases the author has failed to consider?

I don't know.

* Are there any assertion failures or crashes?

No.

* Does the patch slow down simple tests?

No.

* If it claims to improve performance, does it?

n/a

* Does it slow down other things?

No.

* Does it follow the project coding guidelines?

Mostly.

In the src/test/regress/parallel_schedule contains an extra
new line at the end, it shouldn't.

In b/src/backend/optimizer/plan/setrefs.c:

+static void bind_returning_variables(List *rlist, int bef, int aft);

but later it becomes not public:

+ */
+void bind_returning_variables(List *rlist, int bef, int aft)
+{

Strange, but GCC 4.8.1 -Wall doesn't catch it. But the forward
declaration is not needed, the function is called only from
later functions.

Similar for parse_clause.c:

+extern void addAliases(ParseState *pstate);

+void addAliases(ParseState *pstate)

This external declaration is not needed since it is already
in src/include/parser/parse_clause.h

In setrefs.c, bind_returning_variables() I would also rename
the function arguments, so before and after are spelled out.
These are not C keywords.

Some assignments, like:

+   var=(Var*)tle;
and
+   int index_rel=1;

in setrefs.c need spaces.

if() statements need a space before the ( and not after.

Add spaces in the {} list in addAliases():
+   char*aliases[] = {before,after};
like this: { before, after }

Spaces are needed here, too:
+   for(i=0 ; inoal; i++)

This noal should be naliases or n_aliases if you really want
a variable. I would simply use the constant 2 for the two for()
loops in addAliases() instead, its purpose is obvious enough.

In setrefs.c, bind_returning_variables():
+   Var *var = NULL;
+   foreach(temp, rlist){
Add an empty line after the declaration block

Re: [HACKERS] GSOC13 proposal - extend RETURNING syntax

2013-08-21 Thread Boszormenyi Zoltan

Hi,

2013-08-21 20:52 keltezéssel, Karol Trzcionka írta:

W dniu 21.08.2013 19:17, Boszormenyi Zoltan pisze:

With this fixed, a more complete review:

Thanks.

There is a new regression test (returning_before_after.sql) covering
this feature. However, I think it should be added to the group
where returning.sql resides currently. There is a value in running it
in parallel to other tests. Sometimes a subtle bug is uncovered
because of this and your v2 patch fixed such a bug already.

Modified to work correct in parallel testing

doc/src/sgml/ref/update.sgml describes this feature.

doc/src/sgml/dml.sgml should also be touched to cover this feature.
I don't think so, there is not any info about returning feature, I think it shouldn't be 
part of my patch.

In the src/test/regress/parallel_schedule contains an extra
new line at the end, it shouldn't.

Fixed


In b/src/backend/optimizer/plan/setrefs.c:

+static void bind_returning_variables(List *rlist, int bef, int aft);

but later it becomes not public:

+ */
+void bind_returning_variables(List *rlist, int bef, int aft)
+{

I've change to static in the definition.


+extern void addAliases(ParseState *pstate);

+void addAliases(ParseState *pstate)

This external declaration is not needed since it is already
in src/include/parser/parse_clause.h

Removed.


In setrefs.c, bind_returning_variables() I would also rename
the function arguments, so before and after are spelled out.
These are not C keywords.

Changed.

Some assignments, like:

+   var=(Var*)tle;
and
+   int index_rel=1;

in setrefs.c need spaces.

if() statements need a space before the ( and not after.

Add spaces in the {} list in addAliases():
+   char*aliases[] = {before,after};
like this: { before, after }

Spaces are needed here, too:
+   for(i=0 ; inoal; i++)

This noal should be naliases or n_aliases if you really want
a variable. I would simply use the constant 2 for the two for()
loops in addAliases() instead, its purpose is obvious enough.

Added some whitespaces.

In setrefs.c, bind_returning_variables():
+   Var *var = NULL;
+   foreach(temp, rlist){
Add an empty line after the declaration block.

Added.

Other comments:

This #define in pg_class:

diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h
index 49c4f6f..1b09994 100644
--- a/src/include/catalog/pg_class.h
+++ b/src/include/catalog/pg_class.h
@@ -154,6 +154,7 @@ DESCR();
 #define  RELKIND_COMPOSITE_TYPE  'c' /* composite type */
 #define  RELKIND_FOREIGN_TABLE   'f' /* foreign table */
 #define  RELKIND_MATVIEW 'm'   /* materialized view */
+#define  RELKIND_BEFORE 'b'   /* virtual table for 
before/after statements */


 #define  RELPERSISTENCE_PERMANENT 'p' /* regular 
table */
 #define  RELPERSISTENCE_UNLOGGED 'u' /* unlogged permanent 
table */


RELKIND_BEFORE removed - it probably left over previous work and/or I needed it because 
RTE_BEFORE wasn't available (not included?).

Speaking of which, RTE_BEFORE is more properly named
RTE_RETURNING_ALIAS or something like that because it
covers both before and after. Someone may have a better
idea for naming this symbol.

Renamed to RTE_ALIAS - similar to addAliases (not addReturningAliases)


Others may have also a word in this topic, but consider that
this is *not* a regular alias and for those, RTE_ALIAS is not used,
like in

UPDATE table AS alias SET ...

Maybe RTE_RETURNING_ALIAS takes a little more typing, but
it becomes obvious when reading and new code won't confuse
it with regular aliases.


One question, though, about this part:


@@ -1900,7 +1954,27 @@ set_returning_clause_references(PlannerInfo *root,
int rtoffset)
 {
indexed_tlist *itlist;
+   int after_index=0, before_index=0;
+   Query  *parse = root-parse;

+   ListCell   *rt;
+   RangeTblEntry *bef;
+
+   int index_rel=1;
+
+   foreach(rt,parse-rtable)
+   {
+   bef = (RangeTblEntry *)lfirst(rt);
+   if(strcmp(bef-eref-aliasname,after) == 0  bef-rtekind == 
RTE_BEFORE )

+   {
+   after_index = index_rel;
+   }
+   if(strcmp(bef-eref-aliasname,before) == 0  bef-rtekind == 
RTE_BEFORE )

+   {
+   before_index = index_rel;
+   }
+   index_rel++;
+   }
/*
 * We can perform the desired Var fixup by abusing the fix_join_expr
 * machinery that formerly handled inner indexscan fixup.  We search the
@@ -1924,6 +1998,7 @@ set_returning_clause_references(PlannerInfo *root,
resultRelation,
  rtoffset);

+   bind_returning_variables(rlist, before_index, after_index);
pfree(itlist);

return rlist

Re: [HACKERS] UNNEST with multiple args, and TABLE with multiple funcs

2013-08-20 Thread Boszormenyi Zoltan

2013-08-20 08:13 keltezéssel, Pavel Stehule írta:




2013/8/20 David Fetter da...@fetter.org mailto:da...@fetter.org

On Mon, Aug 19, 2013 at 07:45:23PM +0200, Pavel Stehule wrote:
 Hello

 Harder maybe but it may still be cleaner in the long run.
 
   Overall, it's my intention here to remove as many as feasible of the 
old
  reasons why one might use an SRF in the select list.
 
 
  Indeed, it's a big nail in the coffin for SRFs-in-targetlist. Having
  WITH ORDINALITY and this feature, I would vote for removing
  SRF-in-targetlist and call the release PostgreSQL 10.0.
 

 Although I would to remove SRF from targetlist, I don't think so this 
hurry
 strategy is good idea. We should to provide new functionality and old
 functionality one year as minimum, and we should to announce so this
 feature is deprecated

We could do this in 9.3, but all it would be is an announcement, i.e.
no code change of any nature.

 - and maybe use a GUC for disabling, warning and deprecating.



To really ensure backward compatibility, this sentence should read as
add a GUC for disabling *the* warning and deprecating. :-

As I said, I am such an agent provocateur.
Let this side track die and concentrate on the merits of the patch itself. :-)



With utmost respect, I think the general idea of setting SQL grammar
via GUC is a really bad one.  When we've done so in the past, it's
done more harm than good, and we should not repeat it.


so as minumum is controlling warning via GUC, we should to help with identification of 
problematic queries.


Regards

Pavel


 More, I would to see 9.4 release:).

Same here! :)

 x.4 are happy PostgreSQL releases :)

Each one has been at least baseline happy for me since 7.1.  Some have
made me overjoyed, though.

Cheers,
David.
--
David Fetter da...@fetter.org mailto:da...@fetter.org http://fetter.org/
Phone: +1 415 235 3778 tel:%2B1%20415%20235%203778  AIM: dfetter666  
Yahoo!: dfetter
Skype: davidfetter  XMPP: david.fet...@gmail.com 
mailto:david.fet...@gmail.com
iCal: webcal://www.tripit.com/feed/ical/people/david74/tripit.ics
http://www.tripit.com/feed/ical/people/david74/tripit.ics

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate





--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] Backup throttling

2013-08-20 Thread Boszormenyi Zoltan

2013-08-20 08:37 keltezéssel, Heikki Linnakangas írta:

On 19.08.2013 21:15, Boszormenyi Zoltan wrote:

2013-08-19 19:20 keltezéssel, Andres Freund írta:

Based on a quick look it seems like you're throttling on the receiving
side. Is that a good idea? Especially over longer latency links, TCP
buffering will reduce the effect on the sender side considerably.


Throttling on the sender side requires extending the syntax of
BASE_BACKUP and maybe START_REPLICATION so both can be
throttled but throttling is still initiated by the receiver side.


Throttling in the client seems much better to me. TCP is designed to handle a 
slow client.


Maybe throttling the walsender is not a good idea, it can lead
to DoS via disk space shortage.


If a client can initiate a backup and/or streaming replication, he can already do much 
more damage than a DoS via out of disk space. And a nothing stops even a non-privileged 
user from causing an out of disk space situation anyway. IOW that's a non-issue.


I got to the same conclusion this morning, but because of wal_keep_segments.

Best regards,
Zoltán Böszörményi



- Heikki





--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Extension Templates S03E11

2013-08-20 Thread Boszormenyi Zoltan

Hi,

2013-08-04 15:20 keltezéssel, Dimitri Fontaine írta:

Thom Brown t...@linux.com writes:

Could you please resubmit this without using SnapshotNow as it's no longer
supported?

Sure, sorry that I missed that, please find v12 attached.


Here's a review for this patch.

* Is the patch in a patch format which has context? (eg: context diff format)

Yes.

* Does it apply cleanly to the current git master?

No, it has one reject in src/bin/pg_dump/pg_backup_archiver.c.
It was obvious to fix, version 12a is attached.

* Does it include reasonable tests, necessary doc patches, etc?

It has extended the SQL reference nicely but the reference to
xref linkend=extend-extensions was not obvious enough
regarding the list of control parameters.

The SQL syntax has them in allcaps, while the referenced section
has them in lower case. It's easy to miss them while just browsing
for e.g. RELOCATABLE. I had to go back twice to find the proper
part of the text.

I would like to see the control parameters documented in allcaps
in CREATE EXTENSION TEMPLATE. Then ALTER EXTENSION
TEMPLATE should reference the CREATE instead of the longer
text in xref linkend=extend-extensions. This xref can still
be there for reference in all three of CREATE/ALTER/DROP
EXTENSION TEMPLATE.

* Does the patch actually implement what it's supposed to do?

Yes.

* Do we want that?

Yes.

* Do we already have it?

No.

* Does it follow SQL spec, or the community-agreed behavior?

There's no such provision in the spec.
As far as I can tell, it follows the community-agreed behavior.

* Does it include pg_dump support (if applicable)?

Yes.

But the version check is already wrong in src/bin/pg_dump/pg_dump.c
since this patch missed 9.3.

+   /*
+* Before 9.3, there are no extension templates.
+*/
+   if (fout-remoteVersion  90300)
+   {
+   *numExtensionTemplates = 0;
+   return NULL;
+   }
+

* Are there dangers?

I don't think so.

* Have all the bases been covered?

It seems so.

* Does the feature work as advertised?

Yes.

* Are there corner cases the author has failed to consider?

I don't know.

* Are there any assertion failures or crashes?

No.

* Does the patch slow down simple tests?

No.

* If it claims to improve performance, does it?

n/a

* Does it slow down other things?

No.

* Does it follow the project coding guidelines?

Yes.

Nitpicking. This chunk has an extra unnecessary space:

diff --git a/src/backend/catalog/Makefile b/src/backend/catalog/Makefile
index c4d3f3c..689dc37 100644
--- a/src/backend/catalog/Makefile
+++ b/src/backend/catalog/Makefile
@@ -38,6 +38,7 @@ POSTGRES_BKI_SRCS = $(addprefix 
$(top_srcdir)/src/include/catalog/,\
pg_authid.h pg_auth_members.h pg_shdepend.h pg_shdescription.h \
pg_ts_config.h pg_ts_config_map.h pg_ts_dict.h \
pg_ts_parser.h pg_ts_template.h pg_extension.h \
+pg_extension_control.h pg_extension_template.h pg_extension_uptmpl.h \
pg_foreign_data_wrapper.h pg_foreign_server.h pg_user_mapping.h \
pg_foreign_table.h \
pg_default_acl.h pg_seclabel.h pg_shseclabel.h pg_collation.h 
pg_range.h \

* Are there portability issues?

No.

* Will it work on Windows/BSD etc?

It should.

* Are the comments sufficient and accurate?

Yes.

* Does it do what it says, correctly?

According to the added regression tests, yes.

* Does it produce compiler warnings?

No.

* Can you make it crash?

No.

* Is everything done in a way that fits together coherently with other 
features/modules?

I think so.

* Are there interdependencies that can cause problems?

I don't know.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



templates.v12a.patch.gz
Description: Unix tar archive

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] PL/pgSQL PERFORM with CTE

2013-08-20 Thread Boszormenyi Zoltan

2013-08-20 14:35 keltezéssel, David E. Wheeler írta:

On Aug 20, 2013, at 2:31 PM, Pavel Stehule pavel.steh...@gmail.com wrote:


but it works

postgres=# do $$begin with x as (select 10) insert into omega select * from x; 
end;$$;
DO

But this does not:

david=# DO $$
david$# BEGIN
david$# PERFORM * FROM (
david$# WITH inserted AS (
david$# INSERT INTO foo values (1) RETURNING id
david$# ) SELECT inserted.id
david$# ) x;
david$# END;
david$# $$;
ERROR:  WITH clause containing a data-modifying statement must be at the top 
level
LINE 2: WITH inserted AS (
  ^
QUERY:  SELECT * FROM (
 WITH inserted AS (
 INSERT INTO foo values (1) RETURNING id
 ) SELECT inserted.id
 ) x
CONTEXT:  PL/pgSQL function inline_code_block line 3 at PERFORM


This is the same error as if you put the WITH into a subquery,
which is what PERFORM does.

Proof:

SELECT * FROM (
WITH inserted AS (
INSERT INTO foo values (1) RETURNING id
) SELECT inserted.id
) x;


Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] GSOC13 proposal - extend RETURNING syntax

2013-08-20 Thread Boszormenyi Zoltan

Hi,

2013-08-19 21:52 keltezéssel, Boszormenyi Zoltan írta:

2013-08-19 21:21 keltezéssel, Karol Trzcionka írta:

W dniu 19.08.2013 19:56, Boszormenyi Zoltan pisze:

* Does it apply cleanly to the current git master?

No. There's a reject in src/backend/optimizer/plan/initsplan.c

Thank you, merged in attached version.

* Does it include reasonable tests?

Yes but the test fails after trying to fix the rejected chunk of the
patch.

It fails because the HINT was changed, fixed.
That version merges some nested ifs left over from earlier work.


I tried to compile your v5 patch and I got:

initsplan.c: In function ‘add_vars_to_targetlist’:
initsplan.c:216:26: warning: ‘rel’ may be used uninitialized in this function 
[-Wmaybe-uninitialized]

rel-reltargetlist = lappend(rel-reltargetlist,
^

You shouldn't change the assignment at declaration:

- RelOptInfo *rel = find_base_rel(root, var-varno);
+ RelOptInfo *rel;
...
+ if (root-parse-commandType == CMD_UPDATE)
+ {
... (code using rel)
+ }
+ rel = find_base_rel(root, varno);


Let me say it again: the new code in initsplan.c::add_vars_to_targetlist() is 
fishy.
The compiler says that rel used on line 216 may be uninitialized.

Keeping it that way passes make check, perhaps rel was initialized
in a previous iteration of foreach(temp, vars), possibly in the
else if (IsA(node, PlaceHolderVar))
branch, which means that PlaceHolderInfo *phinfo may be interpreted
as RelOptInfo *, stomping on memory.

Moving the assignment back to the declaration makes make check
fail with the attached regression.diffs file.

Initializing it as RelOptInfo *rel = NULL; makes the regression check
die with a segfault, obviously.

Change the code to avoid the warning and still produce the wanted effect.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

*** 
/home/zozo/crosscolumn/review/returning-before-after/postgresql/src/test/regress/expected/returning_before_after.out
2013-08-20 15:01:03.365314482 +0200
--- 
/home/zozo/crosscolumn/review/returning-before-after/postgresql/src/test/regress/results/returning_before_after.out
 2013-08-20 15:30:21.091641454 +0200
***
*** 6,47 
);
  INSERT INTO foo VALUES (1, 'x'),(2,'y');
  UPDATE foo SET bar1=bar1+1 RETURNING before.*, bar1, bar2;
!  bar1 | bar2 | bar1 | bar2 
! --+--+--+--
! 1 | x|2 | x
! 2 | y|3 | y
! (2 rows)
! 
  UPDATE foo SET bar1=bar1-1 RETURNING after.bar1, before.bar1*2;
!  bar1 | ?column? 
! --+--
! 1 |4
! 2 |6
! (2 rows)
! 
  UPDATE foo SET bar1=bar1+1, bar2=bar2 || 'z' RETURNING before.*, after.*;
!  bar1 | bar2 | bar1 | bar2 
! --+--+--+--
! 1 | x|2 | xz
! 2 | y|3 | yz
! (2 rows)
! 
  -- check single after
  UPDATE foo SET bar1=bar1+1, bar2=bar2 || 'a' RETURNING after.*;
!  bar1 | bar2 
! --+--
! 3 | xza
! 4 | yza
! (2 rows)
! 
  -- check single before
  UPDATE foo SET bar1=bar1+1, bar2=bar2 || 'b' RETURNING before.*;
!  bar1 | bar2 
! --+--
! 3 | xza
! 4 | yza
! (2 rows)
! 
  -- it should fail
  UPDATE foo SET bar1=bar1+before.bar1 RETURNING before.*;
  ERROR:  missing FROM-clause entry for table before
--- 6,22 
);
  INSERT INTO foo VALUES (1, 'x'),(2,'y');
  UPDATE foo SET bar1=bar1+1 RETURNING before.*, bar1, bar2;
! ERROR:  no relation entry for relid 2
  UPDATE foo SET bar1=bar1-1 RETURNING after.bar1, before.bar1*2;
! ERROR:  no relation entry for relid 3
  UPDATE foo SET bar1=bar1+1, bar2=bar2 || 'z' RETURNING before.*, after.*;
! ERROR:  no relation entry for relid 2
  -- check single after
  UPDATE foo SET bar1=bar1+1, bar2=bar2 || 'a' RETURNING after.*;
! ERROR:  no relation entry for relid 3
  -- check single before
  UPDATE foo SET bar1=bar1+1, bar2=bar2 || 'b' RETURNING before.*;
! ERROR:  no relation entry for relid 2
  -- it should fail
  UPDATE foo SET bar1=bar1+before.bar1 RETURNING before.*;
  ERROR:  missing FROM-clause entry for table before
***
*** 53,90 
   ^
  -- test before/after aliases
  UPDATE foo AS before SET bar1=bar1+1 RETURNING before.*,after.*;
!  bar1 | bar2 | bar1 | bar2 
! --+--+--+--
! 5 | xzab |5 | xzab
! 6 | yzab |6 | yzab
! (2 rows)
! 
  UPDATE foo AS after SET bar1=bar1-1 RETURNING before.*,after.*;
!  bar1 | bar2 | bar1 | bar2 
! --+--+--+--
! 5 | xzab |4 | xzab
! 6 | yzab |5 | yzab
! (2 rows)
! 
  -- test inheritance
  CREATE TABLE foo2 (bar INTEGER) INHERITS(foo);
  INSERT INTO foo2 VALUES (1,'b',5);
  UPDATE foo2 SET bar1=bar1*2, bar=bar1+5, bar2=bar1::text || bar::text 
RETURNING before.*, after.*, *;
!  bar1 | bar2 | bar | bar1 | bar2 | bar | bar1 | bar2 | bar

Re: [HACKERS] GSOC13 proposal - extend RETURNING syntax

2013-08-20 Thread Boszormenyi Zoltan

2013-08-20 17:30 keltezéssel, Karol Trzcionka írta:

W dniu 20.08.2013 16:47, Karol Trzcionka pisze:

Thank you for the review and tests. New version introduce a lot of
improvements:
- Fix regression test for view (wrong table_name)
- Add regression test for inheritance
- Delete hack in initsplan.c (now we ignore all RTE_BEFORE) - the
uninitialized issue
- Revert changing varno in add_vars_to_targetlist
- Add all before variables to targetlist
- Avoid adding variables to slot for AFTER.
- Treat varnoold like a flag - prevent from adjustment if RTE_BEFORE
- All before/after are now set on OUTER_VAR
- Rename fix_varno_varattno to bind_returning_variables
- Add comment about bind_returning_variables
- Remove unneeded code in fix_join_expr_mutator (it was changing varno
 of RTE_BEFORE - now there is not any var with varno assigned to it)

I've just realized the prepare_returning_before() is unneeded right now
so I've removed it. Version 7, hopefully the last. ;)


Here's a new one, for v7:

setrefs.c: In function ‘set_plan_refs’:
setrefs.c:2001:26: warning: ‘before_index’ may be used uninitialized in this function 
[-Wmaybe-uninitialized]

  bind_returning_variables(rlist, before_index, after_index);
  ^
setrefs.c:1957:21: note: ‘before_index’ was declared here
  int after_index=0, before_index;
 ^

Best regards,
Zoltán Böszörményi


Regards,
Karol Trzcionka





--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] UNNEST with multiple args, and TABLE with multiple funcs

2013-08-19 Thread Boszormenyi Zoltan

Hi,

2013-08-13 15:54 keltezéssel, Andrew Gierth írta:

Summary:

This patch implements a method for expanding multiple SRFs in parallel
that does not have the surprising LCM behaviour of SRFs-in-select-list.
(Functions returning fewer rows are padded with nulls instead.)

It then uses this method combined with a parse-time hack to implement
the (intended to be) spec-conforming behaviour of UNNEST with multiple
parameters, including flattening of composite results.

The upshot is that given a table like this:

postgres=# select * from t1;
a   | b |  c
---+---+--
  {11,12,13}| {wombat}  |
  {5,10}| {foo,bar} | 
{(123,xyzzy),(456,plugh),(789,plover)}
  {21,31,41,51} | {fred,jim,sheila} | {(111,xyzzy),(222,plugh)}
(3 rows)

(where column c is an array of a composite type with 2 cols, x and y)

You can do this:

postgres=# select u.* from t1, unnest(a,b,c) with ordinality as u;
  ?column? | ?column? |  x  |   y| ordinality
--+--+-++
11 | wombat   | ||  1
12 |  | ||  2
13 |  | ||  3
 5 | foo  | 123 | xyzzy  |  1
10 | bar  | 456 | plugh  |  2
   |  | 789 | plover |  3
21 | fred | 111 | xyzzy  |  1
31 | jim  | 222 | plugh  |  2
41 | sheila   | ||  3
51 |  | ||  4
(10 rows)

Or for an example of general combination of functions:

postgres=# select * from table(generate_series(10,20,5), 
unnest(array['fred','jim']));
  ?column? | ?column?
--+--
10 | fred
15 | jim
20 |
(3 rows)

Implementation Details:

The spec syntax for table function calls, table function derived table
in table reference, looks like TABLE(func(args...)) AS ...

This patch implements that, plus an extension: it allows multiple
functions, TABLE(func1(...), func2(...), func3(...)) [WITH ORDINALITY]
and defines this as meaning that the functions are to be evaluated in
parallel.

This is implemented by changing RangeFunction, function RTEs, and the
FunctionScan node to take lists of function calls rather than a single
function. The calling convention for SRFs is completely unchanged; each
function returns its own rows (or a tuplestore in materialize mode) just
as before, and FunctionScan combines the results into a single output
tuple (keeping track of which functions are exhausted in order to
correctly fill in nulls on a backwards scan).

Then, a hack in the parser converts unnest(...) appearing as a
func_table (and only there) into a list of unnest() calls, one for each
parameter.  So

select ... from unnest(a,b,c)

is converted to

select ... from TABLE(unnest(a),unnest(b),unnest(c))

and if unnest appears as part of an existing list inside TABLE(), it's
expanded to multiple entries there too.

This parser hackery is of course somewhat ugly. But given the objective
of implementing the spec's unnest syntax, it seems to be the least ugly
of the possible approaches. (The hard part of doing it any other way
would be generating the description of the result type; composite array
parameters expand into multiple result columns.)


Harder maybe but it may still be cleaner in the long run.


Overall, it's my intention here to remove as many as feasible of the old
reasons why one might use an SRF in the select list.


Indeed, it's a big nail in the coffin for SRFs-in-targetlist. Having
WITH ORDINALITY and this feature, I would vote for removing
SRF-in-targetlist and call the release PostgreSQL 10.0.


  This should also
address the points that Josh brought up in discussion of ORDINALITY
regarding use of SRF-in-select to unnest multiple arrays.

(As a side issue, this patch also sets up pathkeys for ordinality along
the lines of a patch I suggested to Greg a while back in response to
his.)

Current patch status:

This is a first working cut: no docs, no tests, not enough comments, the
deparse logic probably needs more work (it deparses correctly but the
formatting may be suboptimal). However all the functionality is believed
to be in place.


With this last paragraph in mind, I am trying a little review.

* Is the patch in a patch format which has context? (eg: context diff format)

Yes.

* Does it apply cleanly to the current git master?

Applies with some offsets on a few files but without fuzz.

* Does it include reasonable tests, necessary doc patches, etc?

No, as told by the patch author.

* Does the patch actually implement what it's supposed to do?

Yes.

* Do we want that?

Yes.

* Do we already have it?

No.

* Does it follow SQL spec, or the community-agreed behavior?

The SQL spec says these:

In 7.6 table reference

table primary ::=
...
| table 

Re: [HACKERS] Backup throttling

2013-08-19 Thread Boszormenyi Zoltan

2013-07-31 22:50 keltezéssel, Antonin Houska írta:

On 07/31/2013 07:13 AM, Gibheer wrote:

Hi,

That is a really nice feature.

I don't pretend it's my idea, I just coded it. My boss proposed the feature as 
such :-)

I took a first look at your patch and some empty lines you added (e.g. line 60 
your patch). Can you remove
them?

Sure, will do in the next version.

Why did you move localGetCurrentTimestamp() into streamutil.c? Is sys/time.h 
still needed in receivelog.c after the move?
Because both receivelog.c and pg_basebackup.c need it now. I thought I could move 
localTimestampDifference() and localTimestampDifferenceExceeds() as well for the sake of 
consistency (these are actually utilities too) but I didn't get convinced enough that 
the feature alone justifies such a change.


As mentioned in 
http://www.postgresql.org/message-id/20130731173624.gx14...@eldon.alvh.no-ip.org these 
functions ideally shouldn't have separate implementation at all. However the problem is 
that pg_basebackup is not linked to the backend.


Have you considered the src/common directory?



You're right about sys/time.h, it's included via via streamutil.h. I'll fix 
that too.

I will try your patch later today to see, if it works.


Whenever you have time. Thanks!

// Tony


Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] GSOC13 proposal - extend RETURNING syntax

2013-08-19 Thread Boszormenyi Zoltan

Hi,

mini-review follows.


2013-07-22 21:52 keltezéssel, Karol Trzcionka írta:

I've noticed problem with UPDATE ... FROM statement. Fix in new version.
Regards,
Karol


* Does it apply cleanly to the current git master?

No. There's a reject in src/backend/optimizer/plan/initsplan.c

* Does it include reasonable tests?

Yes but the test fails after trying to fix the rejected chunk of the patch.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Backup throttling

2013-08-19 Thread Boszormenyi Zoltan

2013-08-19 19:20 keltezéssel, Andres Freund írta:

Hi,

On 2013-07-24 09:20:52 +0200, Antonin Houska wrote:

Hello,
the purpose of this patch is to limit impact of pg_backup on running server.
Feedback is appreciated.

Based on a quick look it seems like you're throttling on the receiving
side. Is that a good idea? Especially over longer latency links, TCP
buffering will reduce the effect on the sender side considerably.

Greetings,

Andres Freund


Throttling on the sender side requires extending the syntax of
BASE_BACKUP and maybe START_REPLICATION so both can be
throttled but throttling is still initiated by the receiver side.

Maybe throttling the walsender is not a good idea, it can lead
to DoS via disk space shortage.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] UNNEST with multiple args, and TABLE with multiple funcs

2013-08-19 Thread Boszormenyi Zoltan

2013-08-19 20:03 keltezéssel, Josh Berkus írta:

On 08/19/2013 09:23 AM, Boszormenyi Zoltan wrote:

Indeed, it's a big nail in the coffin for SRFs-in-targetlist. Having
WITH ORDINALITY and this feature, I would vote for removing
SRF-in-targetlist and call the release PostgreSQL 10.0.

That's not realistic.


I know. I am such an agent provocateur. :-)


We'd have to deprecate that syntax and
repeatedly and loudly warn people about it for at least 3 years after
the release of 9.3.   You're talking about asking people to refactor
hundreds or thousands of lines of code which makes current use of things
like regex_match() in the target list.




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] [GENERAL] currval and DISCARD ALL

2013-08-19 Thread Boszormenyi Zoltan

Hi,

2013-04-19 16:58 keltezéssel, Fabrízio de Royes Mello írta:


On Fri, Apr 19, 2013 at 11:12 AM, Robert Haas robertmh...@gmail.com 
mailto:robertmh...@gmail.com wrote:


On Fri, Apr 19, 2013 at 10:05 AM, Fabrízio de Royes Mello
fabriziome...@gmail.com mailto:fabriziome...@gmail.com wrote:
 The attached wip patch do that and introduce a subcommand 'SEQUENCES', but
 if we decide to don't add a new subcommand to DISCARD, then its easier to
 modify the patch.

This patch is quite wrong.  It frees seqtab without clearing the
pointer, so the next reference will stomp on memory that may have been
reallocated.  And it doesn't even free seqtab correctly, since it only
frees the first node in the linked list.


Ohh sorry... you're all right... I completely forgot to finish the ReleaseSequenceCaches 
to transverse 'seqtab' linked list and free each node.


The attached patch have this correct code.

Regards,

--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
 Blog sobre TI: http://fabriziomello.blogspot.com
 Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
 Twitter: http://twitter.com/fabriziomello


I am reviewing your patch.

* Is the patch in a patch format which has context? (eg: context diff format)

Yes.

* Does it apply cleanly to the current git master?

Almost. No rejects, no fuzz, only offset for some files.

* Does it include reasonable tests, necessary doc patches, etc?

Documentation, yes. Tests, no.

* Does the patch actually implement what it's supposed to do?

Yes.

* Do we want that?

Yes.

* Do we already have it?

No.

* Does it follow SQL spec, or the community-agreed behavior?

The SQL standard doesn't have DISCARD.
Otherwise the behaviour is obvious.

* Does it include pg_dump support (if applicable)?

n/a

* Are there dangers?

It changes applications' assumptions slightly but takes the
behaviour closer to the wording of the documentation.

* Have all the bases been covered?

Yes.

* Does the feature work as advertised?

Yes.

* Are there corner cases the author has failed to consider?

No.

* Are there any assertion failures or crashes?

No.

* Does the patch slow down simple tests?

No.

* If it claims to improve performance, does it?

n/a

* Does it slow down other things?

No.

* Does it follow the project coding guidelines?

Yes.

Maybe a little stylistic comment:

+void
+ReleaseSequenceCaches()
+{
+   SeqTableData *ptr = seqtab;
+   SeqTableData *tmp = NULL;
+
+   while (ptr != NULL)
+   {
+   tmp = ptr;
+   ptr = ptr-next;
+   free(tmp);
+   }
+
+   seqtab = NULL;
+}

I would rename the variables to seq and next from
ptr and tmp, respectively, to make them even more
obvious. This looks a little better:

+void
+ReleaseSequenceCaches()
+{
+   SeqTableData *seq = seqtab;
+   SeqTableData *next;
+
+   while (seq)
+   {
+   next = seq-next;
+   free(seq);
+   seq = next;
+   }
+
+   seqtab = NULL;
+}

* Are there portability issues?

No.

* Will it work on Windows/BSD etc?

It should. There are no extra system calls.

* Are the comments sufficient and accurate?

The feature needs very little code which is downright obvious.
There are no comments but I don't think the code needs it.

* Does it do what it says, correctly?

Yes.

* Does it produce compiler warnings?

Only one:

src/backend/commands/sequence.c should have

#include commands/sequence.h

because of this:

sequence.c:1608:1: warning: no previous prototype for 'ReleaseSequenceCaches' 
[-Wmissing-prototypes]

 ReleaseSequenceCaches()
 ^

* Can you make it crash?

No.

* Is everything done in a way that fits together coherently with other 
features/modules?

Yes.

* Are there interdependencies that can cause problems?

I don't think so.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] [GENERAL] currval and DISCARD ALL

2013-08-19 Thread Boszormenyi Zoltan

2013-08-19 21:02 keltezéssel, Boszormenyi Zoltan írta:

Hi,

2013-04-19 16:58 keltezéssel, Fabrízio de Royes Mello írta:


On Fri, Apr 19, 2013 at 11:12 AM, Robert Haas robertmh...@gmail.com 
mailto:robertmh...@gmail.com wrote:


On Fri, Apr 19, 2013 at 10:05 AM, Fabrízio de Royes Mello
fabriziome...@gmail.com mailto:fabriziome...@gmail.com wrote:
 The attached wip patch do that and introduce a subcommand 'SEQUENCES', but
 if we decide to don't add a new subcommand to DISCARD, then its easier to
 modify the patch.

This patch is quite wrong.  It frees seqtab without clearing the
pointer, so the next reference will stomp on memory that may have been
reallocated.  And it doesn't even free seqtab correctly, since it only
frees the first node in the linked list.


Ohh sorry... you're all right... I completely forgot to finish the 
ReleaseSequenceCaches to transverse 'seqtab' linked list and free each node.


The attached patch have this correct code.

Regards,

--
Fabrízio de Royes Mello
Consultoria/Coaching PostgreSQL
 Blog sobre TI: http://fabriziomello.blogspot.com
 Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
 Twitter: http://twitter.com/fabriziomello


I am reviewing your patch.

* Is the patch in a patch format which has context? (eg: context diff format)

Yes.

* Does it apply cleanly to the current git master?

Almost. No rejects, no fuzz, only offset for some files.

* Does it include reasonable tests, necessary doc patches, etc?

Documentation, yes. Tests, no.

* Does the patch actually implement what it's supposed to do?

Yes.

* Do we want that?

Yes.

* Do we already have it?

No.

* Does it follow SQL spec, or the community-agreed behavior?

The SQL standard doesn't have DISCARD.
Otherwise the behaviour is obvious.

* Does it include pg_dump support (if applicable)?

n/a

* Are there dangers?

It changes applications' assumptions slightly but takes the
behaviour closer to the wording of the documentation.

* Have all the bases been covered?

Yes.

* Does the feature work as advertised?

Yes.

* Are there corner cases the author has failed to consider?

No.

* Are there any assertion failures or crashes?

No.

* Does the patch slow down simple tests?

No.

* If it claims to improve performance, does it?

n/a

* Does it slow down other things?

No.

* Does it follow the project coding guidelines?

Yes.

Maybe a little stylistic comment:

+void
+ReleaseSequenceCaches()
+{
+   SeqTableData *ptr = seqtab;
+   SeqTableData *tmp = NULL;
+
+   while (ptr != NULL)
+   {
+   tmp = ptr;
+   ptr = ptr-next;
+   free(tmp);
+   }
+
+   seqtab = NULL;
+}

I would rename the variables to seq and next from
ptr and tmp, respectively, to make them even more
obvious. This looks a little better:

+void
+ReleaseSequenceCaches()
+{
+   SeqTableData *seq = seqtab;
+   SeqTableData *next;
+
+   while (seq)
+   {
+   next = seq-next;
+   free(seq);
+   seq = next;
+   }
+
+   seqtab = NULL;
+}

* Are there portability issues?

No.

* Will it work on Windows/BSD etc?

It should. There are no extra system calls.

* Are the comments sufficient and accurate?

The feature needs very little code which is downright obvious.
There are no comments but I don't think the code needs it.

* Does it do what it says, correctly?

Yes.


I lied.

There is one little problem. There is no command tag
reported for DISCARD SEQUENCES:

zozo=# create sequence s1;
CREATE SEQUENCE
zozo=# select nextval('s1');
 nextval
-
   1
(1 row)

zozo=# select currval('s1');
 currval
-
   1
(1 row)

zozo=# discard all;
DISCARD ALL
zozo=# discard sequences;
???
zozo=# select currval('s1');
ERROR:  currval of sequence s1 is not yet defined in this session



* Does it produce compiler warnings?

Only one:

src/backend/commands/sequence.c should have

#include commands/sequence.h

because of this:

sequence.c:1608:1: warning: no previous prototype for 'ReleaseSequenceCaches' 
[-Wmissing-prototypes]

 ReleaseSequenceCaches()
 ^

* Can you make it crash?

No.

* Is everything done in a way that fits together coherently with other 
features/modules?

Yes.

* Are there interdependencies that can cause problems?

I don't think so.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web:http://www.postgresql-support.de
  http://www.postgresql.at/



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] Backup throttling

2013-08-19 Thread Boszormenyi Zoltan

2013-08-19 21:11 keltezéssel, Andres Freund írta:

On 2013-08-19 20:15:51 +0200, Boszormenyi Zoltan wrote:

2013-08-19 19:20 keltezéssel, Andres Freund írta:

Hi,

On 2013-07-24 09:20:52 +0200, Antonin Houska wrote:

Hello,
the purpose of this patch is to limit impact of pg_backup on running server.
Feedback is appreciated.

Based on a quick look it seems like you're throttling on the receiving
side. Is that a good idea? Especially over longer latency links, TCP
buffering will reduce the effect on the sender side considerably.

Throttling on the sender side requires extending the syntax of
BASE_BACKUP and maybe START_REPLICATION so both can be
throttled but throttling is still initiated by the receiver side.

Seems fine to me. Under the premise that the idea is decided to be
worthwile to be integrated. Which I am not yet convinced of.


Maybe throttling the walsender is not a good idea, it can lead
to DoS via disk space shortage.

Not in a measurably different way than receiver side throttling?


No, but that's not what I meant.

START_BACKUP has to deal with big data but it finishes after some time.
But  pg_receivexlog may sit there indefinitely...

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] GSOC13 proposal - extend RETURNING syntax

2013-08-19 Thread Boszormenyi Zoltan

2013-08-19 21:21 keltezéssel, Karol Trzcionka írta:

W dniu 19.08.2013 19:56, Boszormenyi Zoltan pisze:

* Does it apply cleanly to the current git master?

No. There's a reject in src/backend/optimizer/plan/initsplan.c

Thank you, merged in attached version.

* Does it include reasonable tests?

Yes but the test fails after trying to fix the rejected chunk of the
patch.

It fails because the HINT was changed, fixed.
That version merges some nested ifs left over from earlier work.


I tried to compile your v5 patch and I got:

initsplan.c: In function ‘add_vars_to_targetlist’:
initsplan.c:216:26: warning: ‘rel’ may be used uninitialized in this function 
[-Wmaybe-uninitialized]

rel-reltargetlist = lappend(rel-reltargetlist,
^

You shouldn't change the assignment at declaration:

- RelOptInfo *rel = find_base_rel(root, var-varno);
+ RelOptInfo *rel;
...
+ if (root-parse-commandType == CMD_UPDATE)
+ {
... (code using rel)
+ }
+ rel = find_base_rel(root, varno);

Best regards,
Zoltán Böszörményi


Regards,
Karol Trzcionka



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] UNNEST with multiple args, and TABLE with multiple funcs

2013-08-19 Thread Boszormenyi Zoltan

2013-08-19 22:04 keltezéssel, Andrew Gierth írta:

Boszormenyi Zoltan wrote:

This parser hackery is of course somewhat ugly. But given the objective
of implementing the spec's unnest syntax, it seems to be the least ugly
of the possible approaches. (The hard part of doing it any other way
would be generating the description of the result type; composite array
parameters expand into multiple result columns.)

Harder maybe but it may still be cleaner in the long run.

I'm not so sure.

As far as I'm concerned, though, the situation is fairly simple: there
are no proposals on the table for any mechanism that would allow the
deduction of a return type structure for multi-arg unnest, I have
tried and failed to come up with a usable alternative proposal, and
there is no prospect of one resulting from any other work that I know
about. So the parser hack is the way it goes, and anyone who doesn't
like it is welcome to suggest a better idea.


Overall, it's my intention here to remove as many as feasible of the old
reasons why one might use an SRF in the select list.

Indeed, it's a big nail in the coffin for SRFs-in-targetlist. Having
WITH ORDINALITY and this feature, I would vote for removing
SRF-in-targetlist and call the release PostgreSQL 10.0.

I want to make this ABSOLUTELY clear: I am not advocating removing
SRF-in-targetlist in the near future and I will not support anyone who
does. Please do not use this code as an argument for that (at least
until a few releases have elapsed). All I'm interested in at this
point is providing an alternative with better semantics.


The SQL spec says these:

In 7.6 table reference

[mega-snip]

As far as I can tell, these should also be allowed but isn't:

No, they're not allowed. You missed this rule (in 7.6 Syntax Rules):

2) If a table primary TP simply contains a table function derived
table TFDT, then:

a) The collection value expression immediately contained in TFDT
   shall be a routine invocation.

In other words, func(...) is the only allowed form for the collection
value expression inside TABLE( ).  (Same rule exists in 201x, but
numbered 6 rather than 2.)


You are right, I missed it in the standard. Sorry.


Largely as a matter of consistency, the patch does presently allow
expressions that are not routine invocations but which are part of
the func_expr_windowless production, so things like TABLE(USER) work.
(This is because historically these are allowed in the FROM clause as
tables.) I'm not sure this is a good idea in general; should it be
tightened up to only allow func_application?


* If it claims to improve performance, does it?

It certainly improves writing queries, as functions inside
unnest() get processed in one scan.

I'm not making any specific performance claims, but I have tested it
against the idea of doing separate function scans with a full join on
ordinality columns, and my approach is faster (1.5x to 2x in my tests)
even with pathkey support and with elimination of extra materialize
nodes (by allowing mark/restore in FunctionScan).

--

Since the original patch was posted I have done further work on it,
including some tests. I have also come up with an additional
possibility: that of allowing multiple SRFs that return RECORD with
column definition lists, and SRFs-returning-RECORD combined with
ORDINALITY, by extending the syntax further:

select * from TABLE(func1() AS (a text, b integer),
 func2() AS (c integer, d text));

select * from TABLE(func1() AS (a text, b integer))
   WITH ORDINALITY AS f(a,b,o);

-- shame to have to duplicate the column names, but avoiding that would
-- not have been easy

This removes the restriction of the previous ORDINALITY patch that
prevented its use with SRFs that needed coldef lists.


Very nice.


I'm open to other suggestions on the syntax for this.


It's consistent with straight SRFs in FROM, the function
parameters are attached to the functions themselves.
I think it's good as is.


(My implementation of this works by making the column definition list
a property of the function call,


Which also makes it easier on the eyes and brain when reading
someone else's SQL.


  rather than of the RTE or the
FunctionScan node.  This eliminates a few places where TYPEFUNC_RECORD
had to be handled as a special case.)


This is the other plus. No special casing is good.

The only minus is that you haven't attached the new patch. :-)

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


New ECPG idea, was: Re: [HACKERS] ECPG FETCH readahead

2013-08-17 Thread Boszormenyi Zoltan

2013-08-17 12:08 keltezéssel, Boszormenyi Zoltan írta:

Hi,

I am restarting this old thread... :-)

2012-04-24 10:17 keltezéssel, Michael Meskes írta:

OK, I will implement #2. Another question popped up: what to do
with FETCH ALL? The current readahead window size or temporarily
bumping it to say some tens of thousands can be used. We may not
know how much is the all records. This, although lowers performance,
saves memory.

I would say doing a large fetch in two or three batches won't cost too much in
terms of performance.


Please, don't apply this patch yet. I discovered a rather big hole
that can confuse the cursor position tracking if you do this:
...
That will also need a new round of review. Sorry for that.

No problem, better to find it now instead of after release.

Anyway, I moved the patch to 2012-next (I hope I did it correctly) so 2012-1
can be closed. Let's try to get this patch done in the next commit fest.

Michael


I had time to look into this patch of mine again after about 1.5 years.
Frankly, this time was too long to remember every detail of the patch
and looking at parts of the patch as a big entity was confusing.

So I started fresh and to make review easier, I broke the patch up
into small pieces that all build on each other. I have also fixed quite
a few bugs, mostly in my code, but some in the ECPG parser and
the regression tests as well.

I have put the broken up patchset into a GIT tree of mine at GitHub:
https://github.com/zboszor/ecpg-readahead/
but the huge compressed patch is also attached for reference.
It was generated with

$ git diff 
221e92f64c6e136e550ec2592aac3ae0d4623209..870922676e6ae0faa4ebbf94b92e0b97ec418e16


ECPG regression tests are now Valgrind-clean except two of them
but both are pre-existing bugs.

1. ecpg/test/compat_informix/rfmtlong.pgc points out a problem in
   ecpg/compatlib/informix.c

==5036== 1 errors in context 1 of 4:
==5036== Invalid read of size 4
==5036==at 0x4E3453C: rfmtlong (informix.c:941)
==5036==by 0x4007DA: fmtlong.constprop.0 (rfmtlong.pgc:22)
==5036==by 0x4006BE: main (rfmtlong.pgc:45)
==5036==  Address 0x60677d8 is 24 bytes inside a block of size 25 alloc'd
==5036==at 0x4C28409: malloc (in 
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==5036==by 0x4E34268: rfmtlong (informix.c:783)
==5036==by 0x4007DA: fmtlong.constprop.0 (rfmtlong.pgc:22)
==5036==by 0x4006BE: main (rfmtlong.pgc:45)

The same error is reported 4 times.

2. ecpg_add_mem() seems to leak memory:

==5463== 256 bytes in 16 blocks are definitely lost in loss record 1 of 1
==5463==at 0x4C2A121: calloc (in 
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==5463==by 0x4E3E153: ecpg_alloc (memory.c:21)
==5463==by 0x4E3E212: ecpg_add_mem (memory.c:110)
==5463==by 0x4E3542B: ecpg_store_result (execute.c:409)
==5463==by 0x4E37E5A: ecpg_process_output (execute.c:1777)
==5463==by 0x4E38CCA: ecpg_do (execute.c:2137)
==5463==by 0x4E38D8A: ECPGdo (execute.c:2159)
==5463==by 0x400A82: fn (alloc.pgc:51)
==5463==by 0x5152C52: start_thread (pthread_create.c:308)
==5463==by 0x545C13C: clone (clone.S:113)

The last two issue we talked about in this thread are also implemented:
- permanently raise the readahead window if the application sends a
  bigger FETCH command, and
- temporarily raise the readahead window for FETCH ALL commands

The cursor position tracking was completely rewritten, so the client side
properly follows the cursor position known by the backend and doesn't
skip MOVE statements where it shouldn't. The previously known
bug is completely eliminated this way.

Please, review that patch.


I have another idea to make ECPG building on this huge patch.

Currently, UPDATE/DELETE WHERE CURRENT OF has to issue a MOVE
before the command in case the cursor positions known by the application
and the backend are different.

My idea builds on the fact that UPDATE/DELETE RETURNING is present
in all supported back branches.

A mini-parser only understanding SELECT, UPDATE and DELETE should
be added to ecpglib, so

DECLARE cursor CURSOR FOR SELECT ...

and

PREPARE prepared_stmt FROM :query;
DECLARE cursor CURSOR FOR prepared_stmt;

can be analyzed and tweaked behind the application's back.

This is needed to detect whether a query is a simple updatable
scan of a table, and returning errors early to the application if it's not,
without actually sending the UPDATE/DELETE WHERE CURRENT OF
query to the backend.

For the purpose of WHERE CURRENT OF, I would add a ctid
column at the end of the targelist that is treated like resjunk
in the backend when returning data to the application.

So, SELECTs would return the ctid information of the tuples.
The cursor query was a FETCH N with abs(N)1 because of
the readahead. For this reason, the cursor positions known
by the application and the backend are different.

The extra MOVE can be eliminated by replacing

UPDATE table SET ... WHERE CURRENT

Re: [HACKERS] Re: ALTER SYSTEM SET command to change postgresql.conf parameters (RE: Proposal for Allow postgresql.conf values to be changed via SQL [review])

2013-08-06 Thread Boszormenyi Zoltan

2013-08-05 16:01 keltezéssel, Stephen Frost írta:

* Greg Stark (st...@mit.edu) wrote:

On Fri, Aug 2, 2013 at 4:05 PM, Stephen Frost sfr...@snowman.net wrote:

I'm not even clear we do want this in /etc since none of our GUC
options are repeatable things like Apache virtual servers. It actually
makes *more* sense for pg_hba than it does for gucs. I think we can
assume that in the future we'll have something like it however.

I tend to agree with this also, though I can imagine wanting to separate
things in a conf.d directory ala exim's conf.d directories, to allow
tools like puppet to manage certain things environment-wide (perhaps
krb_server_keyfile) while other configuration options are managed
locally.

Extensions are actually a pretty good argument for why conf.d in /etc
(or wherever the non-auto-config is) is pretty important useful.
That's the kind of thing conf.d directories are meant for. A user can
install a package containing an extension and the extension would
automatically drop in the config entries needed in that directory.

Agreed, though I think there should be a difference between shared
library load being added-to for extensions, and random
extension-specific GUC..


Now that you mention shared library load, it may be a good idea
to add an append-to-this-GUC flag instead of overwriting the
previous value. Two GUCs may make use of it: shared_preload_libraries
and local_preload_libraries. It would make packagers' of extensions
and DBA's lives easier.

Best regards,
Zoltán Böszörményi



Thanks,

Stephen



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Re: ALTER SYSTEM SET command to change postgresql.conf parameters (RE: Proposal for Allow postgresql.conf values to be changed via SQL [review])

2013-08-06 Thread Boszormenyi Zoltan

2013-08-06 19:41 keltezéssel, Bruce Momjian írta:

On Tue, Aug  6, 2013 at 06:34:35PM +0200, Boszormenyi Zoltan wrote:

2013-08-05 16:01 keltezéssel, Stephen Frost írta:

* Greg Stark (st...@mit.edu) wrote:

On Fri, Aug 2, 2013 at 4:05 PM, Stephen Frost sfr...@snowman.net wrote:

I'm not even clear we do want this in /etc since none of our GUC
options are repeatable things like Apache virtual servers. It actually
makes *more* sense for pg_hba than it does for gucs. I think we can
assume that in the future we'll have something like it however.

I tend to agree with this also, though I can imagine wanting to separate
things in a conf.d directory ala exim's conf.d directories, to allow
tools like puppet to manage certain things environment-wide (perhaps
krb_server_keyfile) while other configuration options are managed
locally.

Extensions are actually a pretty good argument for why conf.d in /etc
(or wherever the non-auto-config is) is pretty important useful.
That's the kind of thing conf.d directories are meant for. A user can
install a package containing an extension and the extension would
automatically drop in the config entries needed in that directory.

Agreed, though I think there should be a difference between shared
library load being added-to for extensions, and random
extension-specific GUC..

Now that you mention shared library load, it may be a good idea
to add an append-to-this-GUC flag instead of overwriting the
previous value. Two GUCs may make use of it: shared_preload_libraries
and local_preload_libraries. It would make packagers' of extensions
and DBA's lives easier.

'search_path' might also use it, though we might need append and
prepend.


Indeed. Although I was thinking along the lines of the GUC parser, so:

shared_preload_library += 'some_new_lib'

would append to the old value.

Maybe += is intuitive enough for prepending, or someone may
come up with a better idea.

But the extra flag would still be needed to indicate the GUC is a list,
so these new operators are usable on them and not on regular GUCs.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Error code returned by lock_timeout

2013-06-27 Thread Boszormenyi Zoltan

2013-06-27 17:03 keltezéssel, Fujii Masao írta:

On Thu, Jun 27, 2013 at 2:22 PM, Boszormenyi Zoltan z...@cybertec.at wrote:

Hi,

I just realized that in the original incarnation of lock_timeout,
I used ERRCODE_LOCK_NOT_AVAILABLE (to be consistent with NOWAIT)
but the patch that was accepted into 9.3 contained ERRCODE_QUERY_CANCELED
which is the same as for statement_timeout.

Which would be more correct?

ISTM that ERRCODE_LOCK_NOT_AVAILABLE is more suitable...


I think, too. Can someone commit this one-liner to master and 9.3?

Best regards,
Zoltán Bsöszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

--- src/backend/tcop/postgres.c~	2013-06-27 07:05:08.0 +0200
+++ src/backend/tcop/postgres.c	2013-06-27 17:10:28.040972642 +0200
@@ -2900,7 +2900,7 @@
 			DisableNotifyInterrupt();
 			DisableCatchupInterrupt();
 			ereport(ERROR,
-	(errcode(ERRCODE_QUERY_CANCELED),
+	(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
 	 errmsg(canceling statement due to lock timeout)));
 		}
 		if (get_timeout_indicator(STATEMENT_TIMEOUT, true))

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Error code returned by lock_timeout

2013-06-26 Thread Boszormenyi Zoltan

Hi,

I just realized that in the original incarnation of lock_timeout,
I used ERRCODE_LOCK_NOT_AVAILABLE (to be consistent with NOWAIT)
but the patch that was accepted into 9.3 contained ERRCODE_QUERY_CANCELED
which is the same as for statement_timeout.

Which would be more correct?

Thanks in advance,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: ALTER SYSTEM SET command to change postgresql.conf parameters (RE: [HACKERS] Proposal for Allow postgresql.conf values to be changed via SQL [review])

2013-06-18 Thread Boszormenyi Zoltan

Hi,

review below.

2013-06-13 14:35 keltezéssel, Amit Kapila írta:

On Friday, June 07, 2013 9:45 AM Amit Kapila wrote:

On Thursday, June 06, 2013 10:22 PM Robert Haas wrote:

On Wed, Jun 5, 2013 at 7:24 AM, Amit Kapila amit.kap...@huawei.com
wrote:

On Monday, May 27, 2013 4:17 PM Amit Kapila wrote:

On Wednesday, April 03, 2013 11:55 AM Amit Kapila wote:

On Tuesday, April 02, 2013 9:49 PM Peter Eisentraut wrote:

There are 2 options to proceed for this patch for 9.4

1. Upload the SET PERSISTENT syntax patch for coming CF by fixing

existing

review comments
2. Implement new syntax ALTER SYSTEM as proposed in below mail

Could you suggest me what could be best way to proceed for this

patch?

I'm still in favor of some syntax involving ALTER, because it's still
true that this behaves more like the existing GUC-setting commands
that use ALTER (which change configuration for future sessions)

rather

the ones that use SET (which change the current settings for some
period of time).


I will change the patch as per below syntax if there are no objections:

  ALTER SYSTEM SET configuration_parameter {TO | =} {value, | 'value'};

Modified patch contains:

1. Syntax implemented is
ALTER SYSTEM SET configuration_parameter {TO | =} {value, | 'value' |
DEFAULT};

If user specifies DEFAULT, it will remove entry from auto conf file.

2. File name to store settings set by ALTER SYSTEM command is still
persistent.auto.conf

3. Added a new page for Alter System command in docs. In compatability
section, I had mentioned that
this statement is an PostgresQL extension. I had tried to search in
SQL-92 spec but couldn't find such command.

4. During test of this patch, I had observed one problem for PGC_BACKEND
parameters like log_connections.
If I change these parameters directly in postgresql.conf and then do
pg_reload_conf() and reconnect, it will
still show the old value. This is observed only on WINDOWS. I will
investigate this problem and update you.
Due to this problem, I had removed few test cases.


I can't reproduce this error under Linux (Fedora 19/x86_64).

The bug might be somewhere else and not caused by your patch
if manually adding/removing log_connections = on from postgresql.conf
exhibits the same behaviour under Windows. (If I read it correctly,
you tested it exactly this way.) Does the current GIT version behave
the same way?



Kindly let me know your suggestions.

With Regards,
Amit Kapila.


* Is the patch in a patch format which has context?

Yes.

* Does it apply cleanly to the current git master?

Yes.

* Does it include reasonable tests, necessary doc patches, etc?

Yes.

Read what the patch is supposed to do, and consider:

* Does the patch actually implement that?

Yes.

* Do we want that?

Yes.

* Do we already have it?

No.

* Does it follow SQL spec, or the community-agreed behavior?

No such spec, follows the agreed behaviour.

* Does it include pg_dump support (if applicable)?

N/A

* Are there dangers?

No.

* Have all the bases been covered?

According to the above note under Windows, not yet.

The name persistent.auto.conf is not yet set in stone.
postgresql.auto.conf might be better.

Apply the patch, compile it and test:

* Does the feature work as advertised?

Yes, with the noted exception above for log_connections.

* Are there corner cases the author has failed to consider?

I can't see any. It is through

* Are there any assertion failures or crashes?

No.

* Does the patch slow down simple tests?

No.

* If it claims to improve performance, does it?

N/A

* Does it slow down other things?

No.

* Does it follow the project coding guidelines 
http://developer.postgresql.org/pgdocs/postgres/source.html?


Mostly, yes. Some nits, though. At some places, you do:

- ParseConfigFile(ConfigFileName, NULL, true, 0, elevel, head, tail);
+ ParseConfigFile(ConfigFileName, NULL, true, 0, elevel, head, tail,NULL);

without a space between the last comma and the NULL keyword.

Also, in the comment above ParseConfigFile() there are unnecessary
white space changes and spaces at the end of the line.

* Are there portability issues?

No.

* Will it work on Windows/BSD etc?

It should. It doesn't use any platform-dependent code.

* Are the comments sufficient and accurate?

Yes.

* Does it do what it says, correctly?

Yes.

* Does it produce compiler warnings?

No.

* Can you make it crash?

No.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: ALTER SYSTEM SET command to change postgresql.conf parameters (RE: [HACKERS] Proposal for Allow postgresql.conf values to be changed via SQL [review])

2013-06-18 Thread Boszormenyi Zoltan

2013-06-14 05:12 keltezéssel, Amit Kapila írta:

On Friday, June 14, 2013 3:17 AM Josh Berkus wrote:

On 06/13/2013 05:35 AM, Amit Kapila wrote:

On Friday, June 07, 2013 9:45 AM Amit Kapila wrote:

On Thursday, June 06, 2013 10:22 PM Robert Haas wrote:

On Wed, Jun 5, 2013 at 7:24 AM, Amit Kapila

amit.kap...@huawei.com

wrote:

On Monday, May 27, 2013 4:17 PM Amit Kapila wrote:

On Wednesday, April 03, 2013 11:55 AM Amit Kapila wote:

On Tuesday, April 02, 2013 9:49 PM Peter Eisentraut wrote:

There are 2 options to proceed for this patch for 9.4

1. Upload the SET PERSISTENT syntax patch for coming CF by fixing

existing

review comments
2. Implement new syntax ALTER SYSTEM as proposed in below mail

Could you suggest me what could be best way to proceed for this

patch?

I'm still in favor of some syntax involving ALTER, because it's

still

true that this behaves more like the existing GUC-setting commands
that use ALTER (which change configuration for future sessions)

rather

the ones that use SET (which change the current settings for some
period of time).


I will change the patch as per below syntax if there are no

objections:

  ALTER SYSTEM SET configuration_parameter {TO | =} {value, |

'value'};

Modified patch contains:

1. Syntax implemented is
ALTER SYSTEM SET configuration_parameter {TO | =} {value, | 'value' |
DEFAULT};

If user specifies DEFAULT, it will remove entry from auto conf file.

2. File name to store settings set by ALTER SYSTEM command is still
persistent.auto.conf

Why?  Shouldn't it just be auto.conf?  Or system.auto.conf?

   I had kept same name as it was decided for 9.3, but now as command has 
changed so it makes more
   sense to change name as well. I think it can be one of what you suggested or 
postgresql.auto.conf.



I prefer auto.conf, personally.

   Thanks. if no body has any other suggestion I will change it.
   
   I think one of system.auto.conf or postgresql.auto.conf is more appropriate because it either resembles command or existing configuration settings

   file.


I like postgresql.auto.conf better.



With Regards,
Amit Kapila.






--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: ALTER SYSTEM SET command to change postgresql.conf parameters (RE: [HACKERS] Proposal for Allow postgresql.conf values to be changed via SQL [review])

2013-06-18 Thread Boszormenyi Zoltan

2013-06-18 14:11 keltezéssel, Amit Kapila írta:

On Tuesday, June 18, 2013 3:26 PM Boszormenyi Zoltan wrote:

Hi,
review below.

   Thanks for the review.



There are 2 options to proceed for this patch for 9.4
1. Upload the SET PERSISTENT syntax patch for coming CF by fixing
existing
review comments
2. Implement new syntax ALTER SYSTEM as proposed in below mail
Could you suggest me what could be best way to proceed for this
patch?

I'm still in favor of some syntax involving ALTER, because it's still
true that this behaves more like the existing GUC-setting commands
that use ALTER (which change configuration for future sessions)
rather
the ones that use SET (which change the current settings for some
period of time).



I will change the patch as per below syntax if there are no objections:
ALTER SYSTEM SET configuration_parameter {TO | =} {value, | 'value'};

Modified patch contains:
1. Syntax implemented is
ALTER SYSTEM SET configuration_parameter {TO | =} {value, | 'value' |
DEFAULT};
If user specifies DEFAULT, it will remove entry from auto conf file.
2. File name to store settings set by ALTER SYSTEM command is still
persistent.auto.conf
3. Added a new page for Alter System command in docs. In compatability
section, I had mentioned that
   this statement is an PostgresQL extension. I had tried to search in
SQL-92 spec but couldn't find such command.
4. During test of this patch, I had observed one problem for PGC_BACKEND
parameters like log_connections.

If I change these parameters directly in postgresql.conf and then do

pg_reload_conf() and reconnect, it will
   still show the old value. This is observed only on WINDOWS. I will
investigate this problem and update you.
   Due to this problem, I had removed few test cases.

I can't reproduce this error under Linux (Fedora 19/x86_64).
The bug might be somewhere else and not caused by your patch
if manually adding/removing log_connections = on from postgresql.conf
exhibits the same behaviour under Windows. (If I read it correctly,
you tested it exactly this way.) Does the current GIT version behave
the same way?

Yes, the current Git has problem which I had reported in below mail:

http://www.postgresql.org/message-id/009801ce68f7$3a746340$af5d29c0$@kapila@
huawei.com

This problem is not related to this patch, it occurs only on WINDOWS or
under EXEC_BACKEND flag.
I think we can discuss this problem in above mail thread.




* Have all the bases been covered?
According to the above note under Windows, not yet.
The name persistent.auto.conf is not yet set in stone.
postgresql.auto.conf might be better.

I think, the decision of name, we can leave to committer with below
possibilities,
as it is very difficult to build consensus on any particular name.

Auto.conf
System.auto.conf
Postgresql.auto.conf
Persistent.auto.conf


Apply the patch, compile it and test:



* Does it follow the project coding guidelines?
Mostly, yes. Some nits, though. At some places, you do:
- ParseConfigFile(ConfigFileName, NULL, true, 0, elevel, head, tail);
+ ParseConfigFile(ConfigFileName, NULL, true, 0, elevel, head,

tail,NULL);

I think you mean ParseConfigFp()?


Sorry, yes.



without a space between the last comma and the NULL keyword.


Also, in the comment above ParseConfigFile() there are unnecessary
white space changes and spaces at the end of the line.

Do you mean to say whitespaces in below text?

!  * and absolute-ifying the path name if necessary.

!  *
!  * While parsing, it records if it has parsed persistent.auto.conf file.
!  * This information can be used by the callers to ensure if the parameters
!  * set by ALTER SYSTEM SET command will be effective.
*/


Yes.

Anyway, both would be fixed by a pgindent run. (I think.)



With Regards,
Amit Kapila.




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Re: pg_basebackup with -R option and start standby have problems with escaped password

2013-05-17 Thread Boszormenyi Zoltan

2013-05-17 16:05 keltezéssel, Heikki Linnakangas írta:

On 18.02.2013 16:35, Boszormenyi Zoltan wrote:

2013-01-29 11:15 keltezéssel, Magnus Hagander írta:

On Thu, Jan 24, 2013 at 7:04 AM, Hari Babu haribabu.ko...@huawei.com
wrote:

On Wed, Jan 23, 2013 11:48 PM, Magnus Hagander wrote:

On Wed, Jan 23, 2013 at 10:18 AM, Hari Babu haribabu.ko...@huawei.com

wrote:

Test scenario to reproduce:
1. Start the server
2. create the user as follows
./psql postgres -c create user user1 superuser login
password 'use''1'

3. Take the backup with -R option as follows.
./pg_basebackup -D ../../data1 -R -U user1 -W

The following errors are occurring when the new standby on the backup
database starts.

FATAL: could not connect to the primary server: missing = after 1'

in

connection info string

What does the resulting recovery.conf file look like?

The recovery.conf which is generated is as follows

standby_mode = 'on'
primary_conninfo = 'user=''user1'' password=''use''1'' port=''5432'' '


I observed the problem is while reading primary_conninfo from the
recovery.conf file
the function GUC_scanstr removes the quotes of the string and also
makes
the
continuos double quote('') as single quote(').

By using the same connection string while connecting to primary
server the
function conninfo_parse the escape quotes are not able to parse
properly
and it is leading
to problem.

please correct me if any thing wrong in my observation.

Well, it's clearly broken at least :O

Zoltan, do you have time to look at it? I won't have time until at
least after FOSDEM, unfortunately.


I looked at it shortly. What I tried first is adding another pair of single
quotes manually like this:

primary_conninfo = 'user=''user1'' password=''use1''
host=''192.168.1.2'' port=''5432'' sslmode=''disable''
sslcompression=''1'' '

But it doesn't solve the problem either, I got:

FATAL: could not connect to the primary server: missing = after '1'
in connection info string

This worked though:

primary_conninfo = 'user=user1 password=use\'1 host=192.168.1.2
port=5432 sslmode=disable sslcompression=1 '

When I added an elog() to print the conninfo string in libpqrcv_connect(),
I saw that the double quotes were properly eliminated by ParseConfigFp()
in the first case.

So, there is a bug in generating recovery.conf by not double-escaping
the values and another bug in parsing the connection string in libpq
when the parameter value starts with a single-quote character.


No, the libpq connection string parser is working as intended. Per the docs on 
PQconnectdb:


The passed string can be empty to use all default parameters, or it
can contain one or more parameter settings separated by whitespace.
Each parameter setting is in the form keyword = value. Spaces around
the equal sign are optional. To write an empty value, or a value
containing spaces, surround it with single quotes, e.g., keyword = 'a
value'. Single quotes and backslashes within the value must be
escaped with a backslash, i.e., \' and \\.


So, the proper way to escape a quote in a libpq connection string is \', not ''. There 
are two escaping systems layered on top of each other; the recovery.conf parser's, where 
you use '', and the libpq system, where you use \'. So we need two different escaping 
functions in pg_basebackup to get this right.


Why is extending the libpq parser to allow doubling the single
quotes not a good solution? It would be consistent in this regard
with the recovery.conf parser. From this POV the first patch only
needs a little change in the libpq docs.

Also, my patch for libpq only changed the libpq parser when the
parameter argument starts with \'. So in that state the doubled
single quotes should be an accepted escaping in the middle of
the string, too. If you look at the code, there are two branches
that process the argument  differently depending on whether
it starts with a \' or not.



Apart from that, does it bother anyone else that the the primary_conninfo line that 
pg_basebackup creates is butt-ugly?


primary_conninfo = 'user=''heikki'' host=''localhost'' port=''5432'' sslmode=''prefer'' 
sslcompression=''1'' '


Not a single bit. It's machine generated and the code is generic.
The parser can deal with it.



We can't avoid quoting option values that need it, but that's probably very rare in 
practice. I think we should work a bit harder and leave out the quotes where not necessary.


Maybe. :-)


Also, do we really need to include the ssl options when they are the defaults?


I think we were through about this bullet point. IIRC the reasoning and
the consensus was that the backup and the generated recovery.conf
should also work on another machine with a possibly different set of
compilation options for libpq and envvars present on the system.



I think the attached patch fixes the original test scenario correctly, without changing 
libpq's quoting rules, and only quotes when necessary. I didn't do anything about the 
ssl options. Please take

Re: [HACKERS] commit fest schedule for 9.4

2013-05-15 Thread Boszormenyi Zoltan

2013-05-15 20:05 keltezéssel, Andrew Dunstan írta:


On 05/15/2013 02:00 PM, Josh Berkus wrote:

Obviously we need a meta-manager who makes sure we have managers, and is
able to notice that a manager is MIA and needs replaced (or at least
backed-up).

And then a meta-meta-manager to make sure that the meta-manager is
meta-managing.

And an Inspector General.  Anyone have Danny Kaye's phone number?



Or Gogol's?


You have to learn the dialing chant to call them... ;-)



cheers

andrew





--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] 9.3 Beta1 status report

2013-04-22 Thread Boszormenyi Zoltan

2013-04-21 15:10 keltezéssel, Bruce Momjian írta:

On Sun, Apr 21, 2013 at 09:34:10AM +0200, Boszormenyi Zoltan wrote:

2013-04-21 07:02 keltezéssel, Bruce Momjian írta:

I am not sure if Tom shared yet, but we are planning to package 9.3
beta1 on April 29, with a release on May 2.  Those dates might change,
but that is the current plan.  I have completed a draft 9.3 release
notes, which you can view here:

http://momjian.us/pgsql_docs/release-9-3.html

I will be working on polishing them for the next ten days, so any
feedback, patches, or commits are welcome.  I still need to add lots of
SGML markup.

How comes Álvaro's name comes out right in your page but not at
http://www.postgresql.org/docs/devel/static/release-9-3.html ?

Anyway, I attached a patch to fix my name in your page using markups.

Thanks, applied.


Thank you.


   I had not yet gotten to doing the SGML markup for
non-ASCII characters.




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Draft release notes up for review

2013-04-21 Thread Boszormenyi Zoltan

2013-03-29 02:46 keltezéssel, Tom Lane írta:

Since there has been some, um, grumbling about the quality of the
release notes of late, I've prepared draft notes for next week's
releases, covering commits through today.  These are now committed
into the master branch for review, and should show up at
http://www.postgresql.org/docs/devel/static/
after guaibasaurus' next buildfarm run, about three hours from now.

Please comment if you find anything that could be improved.


The sgml converter seems to choke on the UTF-8 characters that my name contains:

Add configuration variable lock_timeout to limit lock wait duration (Zoltán 
Böszörményi)

I don't mind if my name is written without the accented characters like in the 
other entry:

Have pg_basebackup --write-recovery-conf output a minimal recovery.conf (Zoltan 
Boszormenyi, Magnus Hagander)


Alternatively the sgml tool can be taught to emit proper HTML accented 
characters
or my name can be written as Zoltaacute;n Bouml;szouml;rmeacute;nyi

Best regards,
Zoltán Böszörményi



regards, tom lane





--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Draft release notes up for review

2013-04-21 Thread Boszormenyi Zoltan

2013-04-21 08:28 keltezéssel, Boszormenyi Zoltan írta:

2013-03-29 02:46 keltezéssel, Tom Lane írta:

Since there has been some, um, grumbling about the quality of the
release notes of late, I've prepared draft notes for next week's
releases, covering commits through today.  These are now committed
into the master branch for review, and should show up at
http://www.postgresql.org/docs/devel/static/
after guaibasaurus' next buildfarm run, about three hours from now.

Please comment if you find anything that could be improved.


The sgml converter seems to choke on the UTF-8 characters that my name contains:

Add configuration variable lock_timeout to limit lock wait duration (Zoltán 
Böszörményi)


I don't mind if my name is written without the accented characters like in the 
other entry:

Have pg_basebackup --write-recovery-conf output a minimal recovery.conf (Zoltan 
Boszormenyi, Magnus Hagander)


Alternatively the sgml tool can be taught to emit proper HTML accented 
characters
or my name can be written as Zoltaacute;n Bouml;szouml;rmeacute;nyi


doc/src/sgml/release.sgml suggest using the last one but when I looked at
release-9.3, I saw (AlvaroAacute;lvaro Herrera) in the webpage several times
where the sgml contains (Aacute;lvaro Herrera), so it's not bulletproof 
either.



Best regards,
Zoltán Böszörményi



regards, tom lane








--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] 9.3 Beta1 status report

2013-04-21 Thread Boszormenyi Zoltan

2013-04-21 07:02 keltezéssel, Bruce Momjian írta:

I am not sure if Tom shared yet, but we are planning to package 9.3
beta1 on April 29, with a release on May 2.  Those dates might change,
but that is the current plan.  I have completed a draft 9.3 release
notes, which you can view here:

http://momjian.us/pgsql_docs/release-9-3.html

I will be working on polishing them for the next ten days, so any
feedback, patches, or commits are welcome.  I still need to add lots of
SGML markup.


How comes Álvaro's name comes out right in your page but not at
http://www.postgresql.org/docs/devel/static/release-9-3.html ?

Anyway, I attached a patch to fix my name in your page using markups.

Thanks,
Zoltán Böszörményi


--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

diff --git a/doc/src/sgml/release-9.3.sgml b/doc/src/sgml/release-9.3.sgml
index 76ba128..2927272 100644
--- a/doc/src/sgml/release-9.3.sgml
+++ b/doc/src/sgml/release-9.3.sgml
@@ -367,7 +367,7 @@
   listitem
para
 Add configuration variable lock_timeout to limit lock wait duration
-(Zoltán Böszörményi)
+(Zoltaacute;n Bouml;szouml;rmeacute;nyi)
/para
   /listitem
 
@@ -488,7 +488,7 @@
   listitem
para
 Have pg_basebackup --write-recovery-conf output a minimal
-recovery.conf (Zoltan Boszormenyi, Magnus Hagander)
+recovery.conf (Zoltaacute;n Bouml;szouml;rmeacute;nyi, Magnus Hagander)
/para
 
para
@@ -1357,7 +1357,7 @@
 
   listitem
para
-Create a centralized timeout API (Zoltán Böszörményi)
+Create a centralized timeout API (Zoltaacute;n Bouml;szouml;rmeacute;nyi)
/para
   /listitem
 

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Inconsistent DB data in Streaming Replication

2013-04-10 Thread Boszormenyi Zoltan

2013-04-10 18:46 keltezéssel, Fujii Masao írta:

On Wed, Apr 10, 2013 at 11:16 PM, Andres Freund and...@2ndquadrant.com wrote:

On 2013-04-10 10:10:31 -0400, Tom Lane wrote:

Amit Kapila amit.kap...@huawei.com writes:

On Wednesday, April 10, 2013 3:42 PM Samrat Revagade wrote:

Sorry, this is incorrect. Streaming replication continuous, master is not
waiting, whenever the master writes the data page it checks that the WAL
record is written in standby till that LSN.

I am not sure it will resolve the problem completely as your old-master can
have some WAL extra then new-master for same timeline. I don't remember
exactly will timeline switch feature
take care of this extra WAL, Heikki can confirm this point?
Also I think this can serialize flush of data pages in checkpoint/bgwriter
which is currently not the case.

Yeah.  TBH this entire discussion seems to be let's cripple performance
in the normal case so that we can skip doing an rsync when resurrecting
a crashed, failed-over master.  This is not merely optimizing for the
wrong thing, it's positively hazardous.  After a fail-over, you should
be wondering whether it's safe to resurrect the old master at all, not
about how fast you can bring it back up without validating its data.
IOW, I wouldn't consider skipping the rsync even if I had a feature
like this.

Agreed. Especially as in situations where you fall over in a planned
way, e.g. for a hardware upgrade, you can avoid the need to resync with
a littlebit of care.

It's really worth documenting that way.


So its mostly in catastrophic situations this
becomes a problem and in those you really should resync - and its a good
idea not to use a normal rsync but a rsync --checksum or similar.

If database is very large, rsync --checksum takes very long. And I'm concerned
that most of data pages in master has the different checksum from those in the
standby because of commit hint bit. I'm not sure how rsync --checksum can
speed up the backup after failover.


rsync --checksum alone may not but rsync --inplace may speed up backup a 
lot.



Regards,




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [PATCH] Exorcise zero-dimensional arrays (Was: Re: [HACKERS] Should array_length() Return NULL)

2013-04-04 Thread Boszormenyi Zoltan

2013-04-03 20:58 keltezéssel, Gavin Flower írta:

On 04/04/13 05:36, David E. Wheeler wrote:

On Apr 3, 2013, at 9:30 AM, Tom Lanet...@sss.pgh.pa.us  wrote:


Fortran ... Basic ... actually I'd have thought that zero was a
minority position.  Fashions change I guess.

I say we turn the default lower bound up to 11.

David


In keeping with the level of irrationality in this thread, maybe we should set it to an 
irrational number like the square root of 2, or transcend our selves and make in a 
transcendental number like pi!  :-)


I suppose using the square root of minus one would be consider too 
imaginative???  :-)


Nah, that would make arrays have 2 dimensions as a minimum... :-)




Cheers,
Gavin



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-03-18 Thread Boszormenyi Zoltan

2013-03-18 06:47 keltezéssel, Tom Lane írta:

Boszormenyi Zoltan z...@cybertec.at writes:

The volatile marking shouldn't even be necessary there.
The signal handler doesn't writes to it, only the main code.

Well, (a) that's not the case in the patch as committed, and (b) even if
it were true, the volatile marking is still *necessary*, because that's
what tells the compiler it can't optimize away changes to the variable,
say on the grounds of there being another store with no intervening
fetches in the main-line code.  Without that, a compiler that had
aggressively inlined the smaller functions could well deduce that the
disable_alarm() assignment was useless.


Also, since the the variable assignment doesn't depend on other code
in the same function (or vice-versa) the compiler is still free to
reorder it.
Volatile is about not caching the variable in a CPU register since
it's volatile...

I don't believe you understand what volatile is about at all.  Go read
the C standard: it's about requiring objects' values to actually match
the nominal program-specified values at sequence points.  A more
accurate heuristic is that volatile tells the compiler there may be
other forces reading or writing the variable besides the ones it can see
in the current function's source code, and so it can't drop or reorder
accesses to the variable.

regards, tom lane


After reading up on a lot of volatile and memory barriers,
I am still not totally convinced.

For the record, sig_atomit_t is a plain int without any special
treatment from the compiler. It's atomic by nature on every 32-bit
and 64-bit CPU.

How about the attached patch over current GIT? In other words,
why I am wrong with this idea?

The problem that may arise if it's wrong is that transactions are
left waiting for the lock when the interrupt triggers and the variable
is still seen as false from the interrupt handler. But this doesn't happen.

FWIW, this small patch seems to give a 0,7 percent performance
boost for my settings:

shared_buffers = 256MB
work_mem = 8MB
effective_io_concurrency = 8
wal_level = hot_standby
checkpoint_segments = 64
random_page_cost = 1.8

Everything else is the default. I tested the patch on a 8-core
AMD FX-8120 CPU with this pgbench script below. Basically, it's
the default transaction prepended with SET lock_timeout = 1;
I have used the attached quick-and-dirty patch to pgbench to
ignore SQL errors coming from statements. -s 100 was used
to initialize the test database.

\set nbranches 1 * :scale
\set ntellers 10 * :scale
\set naccounts 10 * :scale
\setrandom aid 1 :naccounts
\setrandom bid 1 :nbranches
\setrandom tid 1 :ntellers
\setrandom delta -5000 5000
BEGIN;
SET lock_timeout = 1;
UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, 
:delta, CURRENT_TIMESTAMP);

END;

Results of pgbench -c 32 -j 32 -t 1 -e -f script.sql are
for the GIT version:

tps = 3366.844023 (including connections establishing)
tps = 3367.645454 (excluding connections establishing)

tps = 3379.784707 (including connections establishing)
tps = 3380.622317 (excluding connections establishing)

tps = 3385.198238 (including connections establishing)
tps = 3386.132433 (excluding connections establishing)

and with the barrier patch:

tps = 3412.799044 (including connections establishing)
tps = 3413.670832 (excluding connections establishing)

tps = 3389.796287 (including connections establishing)
tps = 3390.602187 (excluding connections establishing)

tps = 3405.924548 (including connections establishing)
tps = 3406.726997 (excluding connections establishing)

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c
index 3c3e41e..8737a86 100644
--- a/src/backend/utils/misc/timeout.c
+++ b/src/backend/utils/misc/timeout.c
@@ -16,6 +16,7 @@
 
 #include sys/time.h
 
+#include storage/barrier.h
 #include storage/proc.h
 #include utils/timeout.h
 #include utils/timestamp.h
@@ -58,10 +59,10 @@ static timeout_params *volatile active_timeouts[MAX_TIMEOUTS];
  * since the probability of the interrupt actually occurring while we have
  * it disabled is low.	See comments in schedule_alarm() about that.
  */
-static volatile sig_atomic_t alarm_enabled = false;
+static sig_atomic_t alarm_enabled = false;
 
-#define disable_alarm() (alarm_enabled = false)
-#define enable_alarm()	(alarm_enabled = true)
+#define disable_alarm() do { alarm_enabled = false; pg_write_barrier

Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-03-17 Thread Boszormenyi Zoltan

2013-03-17 04:48 keltezéssel, Tom Lane írta:

Boszormenyi Zoltan z...@cybertec.at writes:

  [ 2-lock_timeout-v37.patch ]

Applied after a fair amount of additional hacking.


Thank you, thank you, thank you! :-)


I was disappointed to find that the patch introduced a new race
condition into timeout.c, or at least broke a safety factor that had
been there.  The argument why enable_timeout() could skip disabling
the timer interrupt on entry, if num_active_timeouts is zero, doesn't
work for enable_timeouts(): as soon as you've incremented
num_active_timeouts for the first new timeout, the signal handler would
mess around with the data structure if it were to fire.  What I did
about that was to modify disable_alarm() to forcibly disable the
interrupt if we're adding multiple timeouts in enable_timeouts(), even
if we think no interrupt is pending.  This might be overly paranoid,
but since all of this is new code for 9.3 and hasn't been through any
beta testing, I felt it best to preserve that safety feature.  We can
revisit it later if it proves to be an issue.  (It's conceivable for
instance that we could avoid incrementing the stored value of
num_active_timeouts until we're done adding all the new timeouts;
but that seemed pretty messy.)


Your reasoning seems to be correct. However, if we take it to the
extreme, enable_timeout_at/enable_timeout_after/enable_timeouts
should also disable the interrupt handler at the beginning of the
function and enabled at the end with pqsignal(). An evil soul may
send SIGALRM externally to the backend processes at the proper
moment and create a race condition while enable_timeout*() is in
progress and the itimer is about to trigger at the same time (but
doesn't since it was disabled).


   For the current usage pattern I'm not
too sure that it matters anyway: a savings is only possible if you
have enabled lock_timeout but not statement_timeout, and I'm doubtful
that that will be a common use-case.


I am not too sure about it. With lock_timeout in place, code migrated
from Informix, MSSQL, etc. can have the same semantic behaviour.



I also rearranged the handling of the LOCK_TIMEOUT interrupt some more,
since I didn't see a need for it to be different from STATEMENT_TIMEOUT,
and got rid of some non-C89 coding practices that didn't seem to me to
be improving readability anyway.


Thanks for that, too. I was too blind to see that choice, even after
thinking about why the statement_timeout cannot be done from
SIGALRM context and why does the code need to also send SIGINT
to the process group. (To kill children, too, like scripts executed via
system()...)

Thanks again,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-03-17 Thread Boszormenyi Zoltan

2013-03-17 16:07 keltezéssel, Tom Lane írta:

Boszormenyi Zoltan z...@cybertec.at writes:

2013-03-17 04:48 keltezéssel, Tom Lane írta:

[ worries about stray SIGALRM events ]

Your reasoning seems to be correct. However, if we take it to the
extreme, enable_timeout_at/enable_timeout_after/enable_timeouts
should also disable the interrupt handler at the beginning of the
function and enabled at the end with pqsignal(). An evil soul may
send SIGALRM externally to the backend processes at the proper
moment and create a race condition while enable_timeout*() is in
progress and the itimer is about to trigger at the same time (but
doesn't since it was disabled).

Well, a malefactor with the ability to send signals to a backend
process could also send SIGKILL, or any number of other signals that
would mess things up.  I'm not too concerned about that scenario.
I *am* concerned about leftover timer events, both because this code
isn't very well tested, and because third-party code loaded into the
backend (think pl/perl for instance) could easily set up timer events
we weren't expecting.


I see.


It suddenly occurs to me though that there's more than one way to skin
this cat.  We could easily add another static flag variable called
sigalrm_allowed or some such, and have the signal handler test that
and immediately return without doing anything if it's off.  Clearing
and setting such a variable would be a lot cheaper than an extra
setitimer call, as well as more robust since it would protect us from
all sources of SIGALRM not just ITIMER_REAL.


Something like the attached patch?

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c
index b5a3c8f..314a601 100644
--- a/src/backend/utils/misc/timeout.c
+++ b/src/backend/utils/misc/timeout.c
@@ -49,52 +49,29 @@ static bool all_timeouts_initialized = false;
 static volatile int num_active_timeouts = 0;
 static timeout_params *volatile active_timeouts[MAX_TIMEOUTS];
 
+/*
+ * Safeguard for the signal handler.
+ */
+static volatile bool alarm_enabled = false;
 
 /*
  * Internal helper functions
  *
  * For all of these, it is caller's responsibility to protect them from
- * interruption by the signal handler.	Generally, call disable_alarm()
- * first to prevent interruption, then update state, and last call
+ * interruption by the signal handler.	Generally, set alarm_enabled to false
+ * first to prevent interrupt to do anything, then update state, and last call
  * schedule_alarm(), which will re-enable the interrupt if needed.
- */
-
-/*
- * Disable alarm interrupts
  *
- * multi_insert must be true if the caller intends to activate multiple new
- * timeouts.  Otherwise it should be false.
- */
-static void
-disable_alarm(bool multi_insert)
-{
-	struct itimerval timeval;
+ * There may be a pending interrupt during enable_timeout_at(),
+ * enable_timeout_after() or enablwe_timeouts(). But since alarm_enabled is
+ * false, it is harmless when it triggers. We will reschedule the interrupt
+ * that just fired. In the worst case, it will be late by one unit of the
+ * the timer resolution in the OS.
+ *
+ */
 
-	/*
-	 * If num_active_timeouts is zero, and multi_insert is false, we don't
-	 * have to call setitimer.	There should not be any pending interrupt, and
-	 * even if there is, the worst possible case is that the signal handler
-	 * fires during schedule_alarm.  (If it fires at any point before
-	 * insert_timeout has incremented num_active_timeouts, it will do nothing,
-	 * since it sees no active timeouts.)  In that case we could end up
-	 * scheduling a useless interrupt ... but when the extra interrupt does
-	 * happen, the signal handler will do nothing, so it's all good.
-	 *
-	 * However, if the caller intends to do anything more after first calling
-	 * insert_timeout, the above argument breaks down, since the signal
-	 * handler could interrupt the subsequent operations leading to corrupt
-	 * state.  Out of an abundance of caution, we forcibly disable the timer
-	 * even though it should be off already, just to be sure.  Even though
-	 * this setitimer call is probably useless, we're still ahead of the game
-	 * compared to scheduling two or more timeouts independently.
-	 */
-	if (multi_insert || num_active_timeouts  0)
-	{
-		MemSet(timeval, 0, sizeof(struct itimerval));
-		if (setitimer(ITIMER_REAL, timeval, NULL) != 0)
-			elog(FATAL, could not disable SIGALRM timer: %m);
-	}
-}
+#define disable_alarm() \
+	do { alarm_enabled = false; } while (0)
 
 /*
  * Find

Re: [HACKERS] Re: Proposal for Allow postgresql.conf values to be changed via SQL [review]

2013-03-17 Thread Boszormenyi Zoltan

2013-03-17 17:05 keltezéssel, Greg Smith írta:

On 3/14/13 4:48 PM, Boszormenyi Zoltan wrote:

The attached patch makes
SET PERSISTENT transactional and uses one setting per file.
It uses the currently existing parsing and validating code
and because of this, the patch is half the size of v12 from Amit.


That's not a completely fair comparison, because you lost all the regression testing 
code too.


True.

This does look like a usefully tighter implementation in a few ways, so good progress on 
that.


I still can't see any reason to prefer this one setting per file idea.  As I see it, 
that is pushing the complexity toward the user in a bad way, seemingly just so it's 
easier to implement.  Most of my customers now use tools like Puppet to manage their 
PostgreSQL configuration.  I do not want to have this conversation:


Greg:  You can use SET PERSISTENT to modify settings instead of changing the 
postgresql.conf


User:  That's useful.  How do we adjust Puppet to make sure it picks up the 
changes?

Greg:  You just scan this config directory and add every file that appears in there!  
Each setting will be in its own file.


User:  shocked look  It creates new files?  That isn't going to fit into our version 
control approach easily.  Can we disable this feature so no one accidentally uses it?


I'm not exaggerating here--one setting per file makes this feature less than useless 
to me.  It becomes something where I will have to waste time defending against people 
using it.  I'd prefer to not have this at all than to do it that way.


That we're breaking these settings off into their own file, instead of trying to edit 
the postgresql.conf, to me is a pragmatic trade-off to keep the implementation from 
being really complicated.  It's also a step forward in a larger series for how to 
improve configuration management.  Just because that change introduces an entire 
directory being scanned, I don't see that as an excuse to clutter it with a long list of 
files too.


OK. I just wanted to show an alternative implementation.

I admit, I haven't read all mails from this thread so I don't know
how important for this feature to be non-transactional, or
whether it would be better to be transactional.

The one-file-to-rule-them-all approach can also be added to this
patch as well, but synchronizing transactions over parsing and
rewriting the extra file would decrease the relaxed effects of
synchronous_commit. On the other hand, writing out one file
per setting, although atomic to the level of one file, cannot be
guaranteed to be atomic as a whole for all settings changed
in the transaction without some synchronization.

As far as I can see, AtEOXact_GUC() is called outside the
critical section and is not synchronized any other way.
(Currently, there's no need to.)

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-03-17 Thread Boszormenyi Zoltan

2013-03-18 03:52 keltezéssel, Tom Lane írta:

Boszormenyi Zoltan z...@cybertec.at writes:

2013-03-17 16:07 keltezéssel, Tom Lane írta:

It suddenly occurs to me though that there's more than one way to skin
this cat.  We could easily add another static flag variable called
sigalrm_allowed or some such, and have the signal handler test that
and immediately return without doing anything if it's off.  Clearing
and setting such a variable would be a lot cheaper than an extra
setitimer call, as well as more robust since it would protect us from
all sources of SIGALRM not just ITIMER_REAL.

Something like the attached patch?

Well, something like that, but it still needed some improvements.  In
particular I thought it best to leave the signal handler still releasing
the procLatch unconditionally --- that behavior is independent of what
this module is doing.  Also you seem to have some odd ideas about what
do-while will accomplish.  AFAIK, in this usage it's purely a syntactic
trick without much semantic content.  It's the marking of the variable
as volatile that counts for telling the compiler not to re-order
operations.


The volatile marking shouldn't even be necessary there.
The signal handler doesn't writes to it, only the main code.
I just put it there saying why not? to myself.
IIRC, volatile is needed if both the signal handler and the
main code changes the same variable.

I got the reordering idea from here:
http://yarchive.net/comp/linux/compiler_barriers.html

Thanks for committing,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-03-17 Thread Boszormenyi Zoltan

2013-03-18 06:22 keltezéssel, Boszormenyi Zoltan írta:

2013-03-18 03:52 keltezéssel, Tom Lane írta:

Boszormenyi Zoltan z...@cybertec.at writes:

2013-03-17 16:07 keltezéssel, Tom Lane írta:

It suddenly occurs to me though that there's more than one way to skin
this cat.  We could easily add another static flag variable called
sigalrm_allowed or some such, and have the signal handler test that
and immediately return without doing anything if it's off. Clearing
and setting such a variable would be a lot cheaper than an extra
setitimer call, as well as more robust since it would protect us from
all sources of SIGALRM not just ITIMER_REAL.

Something like the attached patch?

Well, something like that, but it still needed some improvements.  In
particular I thought it best to leave the signal handler still releasing
the procLatch unconditionally --- that behavior is independent of what
this module is doing.  Also you seem to have some odd ideas about what
do-while will accomplish.  AFAIK, in this usage it's purely a syntactic
trick without much semantic content.  It's the marking of the variable
as volatile that counts for telling the compiler not to re-order
operations.


The volatile marking shouldn't even be necessary there.
The signal handler doesn't writes to it, only the main code.
I just put it there saying why not? to myself.
IIRC, volatile is needed if both the signal handler and the
main code changes the same variable.


Also, since the the variable assignment doesn't depend on other code
in the same function (or vice-versa) the compiler is still free to
reorder it.

Volatile is about not caching the variable in a CPU register since
it's volatile...



I got the reordering idea from here:
http://yarchive.net/comp/linux/compiler_barriers.html

Thanks for committing,
Zoltán Böszörményi




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-03-16 Thread Boszormenyi Zoltan

2013-03-15 18:53 keltezéssel, Tom Lane írta:

Boszormenyi Zoltanz...@cybertec.at  writes:

[ 2-lock_timeout-v33.patch ]

I looked at this patch a bit.  I don't understand why you've chosen to
alter the API of the enable_timeout variants to have a bool result that
says I didn't bother to process the timeout because it would have fired
immediately.


I don't know either...


   That is not an advantage for any call site that I can
see: it just means that the caller needs an extra, very difficult to
test code path to handle what would normally be handled by a timeout
interrupt.  Even if it were a good API choice, you've broken a number of
existing call sites that the patch fails to touch (eg in postmaster.c
and postgres.c).  It's not acceptable to define a failure return from
enable_timeout_after and then let callers assume that the failure can't
happen.

Please undo that.


Done.


Also, I'm not really enamored of the choice to use List* infrastructure
for enable_timeouts().  That doesn't appear to be especially convenient
for any caller, and what it does do is create memory-leak risks for most
of them (if they forget to free the list cells, perhaps as a result of
an error exit).  I think a local-variable array of TimeoutParams[]
structs would serve better for most use-cases.


Changed. However, the first member of the structure is
TimeoutId id and a sensible end-of-array value can be -1.
Some versions of GCC (maybe other compilers, too) complain
if a constant is assigned to an enum which is outside of the
declared values of the enum. So I added a NO_TIMEOUT = -1
to enum TimeoutId. Comments?


Another thought is that the PGSemaphoreTimedLock implementations all
share the same bug, which is that if the condition callback returns
true immediately after we acquire the semaphore, they will all wrongly
return false indicating that the semaphore wasn't acquired.


You are right. Fixed.


   (BTW,
I do not like either the variable name condition or the typedef name
TimeoutCondition for something that's actually a callback function
pointer.)


How about TimeoutCallback and callback_fn?


In the same vein, this comment change:

* NOTE: Think not to put any shared-state cleanup after the call to
* ProcSleep, in either the normal or failure path.  The lock state must
!  * be fully set by the lock grantor, or by CheckDeadLock if we give up
!  * waiting for the lock.  This is necessary because of the possibility
!  * that a cancel/die interrupt will interrupt ProcSleep after someone else
!  * grants us the lock, but before we've noticed it. Hence, after granting,
!  * the locktable state must fully reflect the fact that we own the lock;
!  * we can't do additional work on return.
*
* We can and do use a PG_TRY block to try to clean up after failure, but
* this still has a major limitation: elog(FATAL) can occur while waiting
--- 1594,1606 
   /*
* NOTE: Think not to put any shared-state cleanup after the call to
* ProcSleep, in either the normal or failure path.  The lock state must
!  * be fully set by the lock grantor, or by CheckDeadLock or by ProcSleep
!  * itself in case a timeout is detected or if we give up waiting for the 
lock.
!  * This is necessary because of the possibility that a cancel/die 
interrupt
!  * will interrupt ProcSleep after someone else grants us the lock, but
!  * before we've noticed it. Hence, after granting, the locktable state 
must
!  * fully reflect the fact that we own the lock; we can't do additional 
work
!  * on return.
*

suggests that you've failed to grasp the fundamental race-condition
problem here.  ProcSleep can't do cleanup after the fact any more than
its callers can, because otherwise it has a race condition with some
other process deciding to grant it the lock at about the same time its
timeout goes off.  I think the changes in ProcSleep that alter the
state-cleanup behavior are just plain wrong, and what you need to do
is make that look more like the existing mechanisms that clean up when
statement timeout occurs.


This was the most enlightening comment up to now.
It seems no one else understood the timer code but you...
Thanks very much.

I hope the way I did it is right. I factored out the core of
StatementCancelHandler() into a common function that can
be used by the lock_timeout interrupt as its timeout callback
function. Now the code doesn't need PGSemaphoreTimedLock().

While I was thinking about how this thing works, I recognized
that I also need to set the timeout indicator to false after checking
it in ProcessInterrupts().

The reason is that it's needed is this scenario:
1. lock_timeout is set and the transaction throws its error
2. lock_timeout is unset before the next transaction
3. the user presses Ctrl-C during the next transaction
In  this case, the second transaction would report the
lock timeout error, since the indicator was still 

Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-03-16 Thread Boszormenyi Zoltan

2013-03-16 17:42 keltezéssel, Tom Lane írta:

Boszormenyi Zoltan z...@cybertec.at writes:

2013-03-15 18:53 keltezéssel, Tom Lane írta:

Also, I'm not really enamored of the choice to use List* infrastructure
for enable_timeouts().

Changed. However, the first member of the structure is
TimeoutId id and a sensible end-of-array value can be -1.
Some versions of GCC (maybe other compilers, too) complain
if a constant is assigned to an enum which is outside of the
declared values of the enum. So I added a NO_TIMEOUT = -1
to enum TimeoutId. Comments?

I was thinking more of having array pointer and count parameters, ie
enable_timeouts(TimeoutParams *timeouts, int n)
I guess we could do it with sentinels instead but not sure that's
better.

The sentinel approach might be all right if there was another reason
to have an invalid value in the enum, but I'm not seeing one ATM.


Stephen Frost was against the array pointer/count variant,
it was done that way earlier. Let me redo it again. :-)




I hope the way I did it is right. I factored out the core of
StatementCancelHandler() into a common function that can
be used by the lock_timeout interrupt as its timeout callback
function. Now the code doesn't need PGSemaphoreTimedLock().

Hm, not needing PGSemaphoreTimedLock at all is an improvement for
sure.  Don't have time right now to look closer though.

regards, tom lane





--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index ae6ee60..c554ab1 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5080,7 +5080,10 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
 milliseconds, starting from the time the command arrives at the server
 from the client.  If varnamelog_min_error_statement/ is set to
 literalERROR/ or lower, the statement that timed out will also be
-logged.  A value of zero (the default) turns this off.
+logged.  The timeout may happen any time, i.e. while waiting for locks
+on database objects or in case of a large result set, during data
+retrieval from the server after all locks were successfully acquired.
+A value of zero (the default) turns this off.
/para
 
para
@@ -5091,6 +5094,33 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
   /listitem
  /varlistentry
 
+ varlistentry id=guc-lock-timeout xreflabel=lock_timeout
+  termvarnamelock_timeout/varname (typeinteger/type)/term
+  indexterm
+   primaryvarnamelock_timeout/ configuration parameter/primary
+  /indexterm
+  listitem
+   para
+Abort any statement which waits longer than the specified number of
+milliseconds while attempting to acquire a lock on rows, pages,
+tables, indices or other objects. The timeout applies to each of
+the locks individually.
+   /para
+   para
+As opposed to varnamestatement_timeout/, this timeout (and the error)
+may only occur while waiting for locks. If varnamelog_min_error_statement/
+is set to literalERROR/ or lower, the statement that timed out will
+also be logged. A value of zero (the default) turns this off.
+   /para
+
+   para
+Setting varnamelock_timeout/ in
+filenamepostgresql.conf/ is not recommended because it
+affects all sessions.
+   /para  
+  /listitem   
+ /varlistentry
+
  varlistentry id=guc-vacuum-freeze-table-age xreflabel=vacuum_freeze_table_age
   termvarnamevacuum_freeze_table_age/varname (typeinteger/type)/term
   indexterm
diff --git a/doc/src/sgml/ref/lock.sgml b/doc/src/sgml/ref/lock.sgml
index 05acbc4..3de08d5 100644
--- a/doc/src/sgml/ref/lock.sgml
+++ b/doc/src/sgml/ref/lock.sgml
@@ -39,10 +39,12 @@ LOCK [ TABLE ] [ ONLY ] replaceable class=PARAMETERname/replaceable [ * ]
literalNOWAIT/literal is specified, commandLOCK
TABLE/command does not wait to acquire the desired lock: if it
cannot be acquired immediately, the command is aborted and an
-   error is emitted.  Once obtained, the lock is held for the
-   remainder of the current transaction.  (There is no commandUNLOCK
-   TABLE/command command; locks are always released at transaction
-   end.)
+   error is emitted. If varnamelock_timeout/varname is set and
+   the lock cannot be acquired under the specified timeout,
+   the command is aborted and an error is emitted. Once obtained,
+   the lock is held for the remainder of the current transaction.
+   (There is no commandUNLOCK TABLE/command command; locks are
+   always released at transaction end.)
   /para
 
   para
diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml
index 1d3f854..e7106b2 100644

Re: [HACKERS] Re: Proposal for Allow postgresql.conf values to be changed via SQL [review]

2013-03-15 Thread Boszormenyi Zoltan

2013-03-15 00:48 keltezéssel, Boszormenyi Zoltan írta:

2013-03-13 21:28 keltezéssel, Boszormenyi Zoltan írta:

2013-03-13 13:45 keltezéssel, Andres Freund írta:

On 2013-03-13 09:09:24 +0100, Boszormenyi Zoltan wrote:

2013-03-13 07:42 keltezéssel, Craig Ringer írta:

On 03/12/2013 06:27 AM, Craig Ringer wrote:

Think also about the case where someone wants to change multiple
values together and having just some set and not others would be
inconsistent.

Yeah, that's a killer. The reload would need to be scheduled for COMMIT
time, it can't be done by `SET PERSISTENT` directly.

Thinking about this some more, I'm not sure this is a good idea.

Right now, SET takes effect immediately. Always, without exception.
Delaying SET PERSISTENT's effects until commit would make it
inconsistent with SET's normal behaviour.

However, *not* delaying it would make it another quirky
not-transactional not-atomic command. That's OK, but if it's not going
to follow transactional semantics it should not be allowed to run within
a transaction, like VACUUM .

Writing the changes immediately but deferring the reload until commit
seems to be the worst of those two worlds.

I was thinking about it a little. There is a hook that runs at the end
of (sub-)transactions. It can be abused for this purpose to make
SET PERSISTENT transactional. The subtransactions can also stack
these settings, by forgetting settings upon ROLLBACK [ TO SAVEPOINT ]
and overwriting previous settings upon COMMIT and RELEASE SAVEPOINT.
All it needs is a list and maintaining intermediate pointers when entering
into a new level of SAVEPOINT. The functions to register such hooks are
in src/include/access/xact.h:

extern void RegisterXactCallback(XactCallback callback, void *arg);
extern void UnregisterXactCallback(XactCallback callback, void *arg);
extern void RegisterSubXactCallback(SubXactCallback callback, void *arg);
extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg);

(sub)xact commit/abort already calls AtEOXact_GUC(commit, nestlevel). So you
wouldn't even need that.


Yes, thanks.


  It seems we could add another value to enum
GucStackState, like GUC_SET_PERSISTENT - and process those only if commit 
nestlevel == 1.


Maybe it's not needed, only enum GucAction needs a new
GUC_ACTION_PERSISTENT value since that's what has any
business in push_old_value(). Adding two new members to
GucStack like these are enough
bool has_persistent;
config_var_value persistent;
and SET PERSISTENT can be treated as GUC_SET. push_old_value()
can merge GUC values set in the same transaction level.


It seems both were needed. The attached patch makes
SET PERSISTENT transactional and uses one setting per file.
It uses the currently existing parsing and validating code
and because of this, the patch is half the size of v12 from Amit.


The only missing piece is the check for superuser.




Best regards,
Zoltán Böszörményi




Everytime you see one with commit  nestlevel  1 you put them into them into
the stack one level up.

This seems like its somewhat in line with the way SET LOCAL is implemented?


On the other hand, it would make a lot of sense to implement it
as one setting per file or extending the  code to allow modifying
settings in bulk. The one setting per file should be easier and
it would also allow extensions to drop their settings automatically
into the automatic config directory. I don't know who mentioned
this idea about extensions but it also came up a while back.

I still think one-setting-per-file is the right way to go, yes.

Greetings,

Andres Freund












--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] Re: Proposal for Allow postgresql.conf values to be changed via SQL [review]

2013-03-14 Thread Boszormenyi Zoltan

2013-03-13 21:28 keltezéssel, Boszormenyi Zoltan írta:

2013-03-13 13:45 keltezéssel, Andres Freund írta:

On 2013-03-13 09:09:24 +0100, Boszormenyi Zoltan wrote:

2013-03-13 07:42 keltezéssel, Craig Ringer írta:

On 03/12/2013 06:27 AM, Craig Ringer wrote:

Think also about the case where someone wants to change multiple
values together and having just some set and not others would be
inconsistent.

Yeah, that's a killer. The reload would need to be scheduled for COMMIT
time, it can't be done by `SET PERSISTENT` directly.

Thinking about this some more, I'm not sure this is a good idea.

Right now, SET takes effect immediately. Always, without exception.
Delaying SET PERSISTENT's effects until commit would make it
inconsistent with SET's normal behaviour.

However, *not* delaying it would make it another quirky
not-transactional not-atomic command. That's OK, but if it's not going
to follow transactional semantics it should not be allowed to run within
a transaction, like VACUUM .

Writing the changes immediately but deferring the reload until commit
seems to be the worst of those two worlds.

I was thinking about it a little. There is a hook that runs at the end
of (sub-)transactions. It can be abused for this purpose to make
SET PERSISTENT transactional. The subtransactions can also stack
these settings, by forgetting settings upon ROLLBACK [ TO SAVEPOINT ]
and overwriting previous settings upon COMMIT and RELEASE SAVEPOINT.
All it needs is a list and maintaining intermediate pointers when entering
into a new level of SAVEPOINT. The functions to register such hooks are
in src/include/access/xact.h:

extern void RegisterXactCallback(XactCallback callback, void *arg);
extern void UnregisterXactCallback(XactCallback callback, void *arg);
extern void RegisterSubXactCallback(SubXactCallback callback, void *arg);
extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg);

(sub)xact commit/abort already calls AtEOXact_GUC(commit, nestlevel). So you
wouldn't even need that.


Yes, thanks.


  It seems we could add another value to enum
GucStackState, like GUC_SET_PERSISTENT - and process those only if commit 
nestlevel == 1.


Maybe it's not needed, only enum GucAction needs a new
GUC_ACTION_PERSISTENT value since that's what has any
business in push_old_value(). Adding two new members to
GucStack like these are enough
bool has_persistent;
config_var_value persistent;
and SET PERSISTENT can be treated as GUC_SET. push_old_value()
can merge GUC values set in the same transaction level.


It seems both were needed. The attached patch makes
SET PERSISTENT transactional and uses one setting per file.
It uses the currently existing parsing and validating code
and because of this, the patch is half the size of v12 from Amit.

Best regards,
Zoltán Böszörményi




Everytime you see one with commit  nestlevel  1 you put them into them into
the stack one level up.

This seems like its somewhat in line with the way SET LOCAL is implemented?


On the other hand, it would make a lot of sense to implement it
as one setting per file or extending the  code to allow modifying
settings in bulk. The one setting per file should be easier and
it would also allow extensions to drop their settings automatically
into the automatic config directory. I don't know who mentioned
this idea about extensions but it also came up a while back.

I still think one-setting-per-file is the right way to go, yes.

Greetings,

Andres Freund







--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index ae6ee60..8713fd8 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -158,6 +158,22 @@ SET ENABLE_SEQSCAN TO OFF;
  require superuser permission to change via commandSET/command or
  commandALTER/.
 /para
+
+para
+ Another way to change configuration parameters persistently is by 
+ use of xref linkend=SQL-SET
+ command, for example:
+screen
+SET PERSISTENT max_connections To 10;
+/screen
+ This command will allow users to change values persistently 
+ through SQL command. The new value will be effective immediately in
+ the session and the last persistent value for a transaction is
+ committed into its own configuration file. It becomes effective
+ cluster-wide after reloading the server configuration (acronymSIGHUP/)
+ or server startup. The effect of this command is similar to when
+ user manually changes values in filenamepostgresql.conf/filename.  
+/para
/sect2
 
sect2 id=config-setting-examining
diff --git a/doc/src/sgml/keywords.sgml b/doc/src/sgml/keywords.sgml
index 576fd65..ed19784 100644
--- a/doc/src/sgml/keywords.sgml
+++ b/doc/src/sgml/keywords.sgml
@@ -3388,6 +3388,13 @@
 entry/entry
/row

Re: [HACKERS] Re: Proposal for Allow postgresql.conf values to be changed via SQL [review]

2013-03-13 Thread Boszormenyi Zoltan

2013-03-13 07:42 keltezéssel, Craig Ringer írta:

On 03/12/2013 06:27 AM, Craig Ringer wrote:

Think also about the case where someone wants to change multiple
values together and having just some set and not others would be
inconsistent.

Yeah, that's a killer. The reload would need to be scheduled for COMMIT
time, it can't be done by `SET PERSISTENT` directly.

Thinking about this some more, I'm not sure this is a good idea.

Right now, SET takes effect immediately. Always, without exception.
Delaying SET PERSISTENT's effects until commit would make it
inconsistent with SET's normal behaviour.

However, *not* delaying it would make it another quirky
not-transactional not-atomic command. That's OK, but if it's not going
to follow transactional semantics it should not be allowed to run within
a transaction, like VACUUM .

Writing the changes immediately but deferring the reload until commit
seems to be the worst of those two worlds.


I was thinking about it a little. There is a hook that runs at the end
of (sub-)transactions. It can be abused for this purpose to make
SET PERSISTENT transactional. The subtransactions can also stack
these settings, by forgetting settings upon ROLLBACK [ TO SAVEPOINT ]
and overwriting previous settings upon COMMIT and RELEASE SAVEPOINT.
All it needs is a list and maintaining intermediate pointers when entering
into a new level of SAVEPOINT. The functions to register such hooks are
in src/include/access/xact.h:

extern void RegisterXactCallback(XactCallback callback, void *arg);
extern void UnregisterXactCallback(XactCallback callback, void *arg);
extern void RegisterSubXactCallback(SubXactCallback callback, void *arg);
extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg);

The per-session local effect can also be immediate, it just needs
the normal SET and SET PERSISTENT code paths to be unified.

On the other hand, it would make a lot of sense to implement it
as one setting per file or extending the  code to allow modifying
settings in bulk. The one setting per file should be easier and
it would also allow extensions to drop their settings automatically
into the automatic config directory. I don't know who mentioned
this idea about extensions but it also came up a while back.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Re: Proposal for Allow postgresql.conf values to be changed via SQL [review]

2013-03-13 Thread Boszormenyi Zoltan

2013-03-13 09:09 keltezéssel, Boszormenyi Zoltan írta:

2013-03-13 07:42 keltezéssel, Craig Ringer írta:

On 03/12/2013 06:27 AM, Craig Ringer wrote:

Think also about the case where someone wants to change multiple
values together and having just some set and not others would be
inconsistent.

Yeah, that's a killer. The reload would need to be scheduled for COMMIT
time, it can't be done by `SET PERSISTENT` directly.

Thinking about this some more, I'm not sure this is a good idea.

Right now, SET takes effect immediately. Always, without exception.
Delaying SET PERSISTENT's effects until commit would make it
inconsistent with SET's normal behaviour.

However, *not* delaying it would make it another quirky
not-transactional not-atomic command. That's OK, but if it's not going
to follow transactional semantics it should not be allowed to run within
a transaction, like VACUUM .

Writing the changes immediately but deferring the reload until commit
seems to be the worst of those two worlds.


I was thinking about it a little. There is a hook that runs at the end
of (sub-)transactions. It can be abused for this purpose to make
SET PERSISTENT transactional. The subtransactions can also stack
these settings, by forgetting settings upon ROLLBACK [ TO SAVEPOINT ]
and overwriting previous settings upon COMMIT and RELEASE SAVEPOINT.


By overwriting at RELEASE SAVEPOINT I meant only the memory copy
so the value that was set last is remembered at the same level of subxact.
The final settings make it to the configuration file at COMMIT time.


All it needs is a list and maintaining intermediate pointers when entering
into a new level of SAVEPOINT. The functions to register such hooks are
in src/include/access/xact.h:

extern void RegisterXactCallback(XactCallback callback, void *arg);
extern void UnregisterXactCallback(XactCallback callback, void *arg);
extern void RegisterSubXactCallback(SubXactCallback callback, void *arg);
extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg);

The per-session local effect can also be immediate, it just needs
the normal SET and SET PERSISTENT code paths to be unified.

On the other hand, it would make a lot of sense to implement it
as one setting per file or extending the  code to allow modifying
settings in bulk. The one setting per file should be easier and
it would also allow extensions to drop their settings automatically
into the automatic config directory. I don't know who mentioned
this idea about extensions but it also came up a while back.

Best regards,
Zoltán Böszörményi




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Re: Proposal for Allow postgresql.conf values to be changed via SQL [review]

2013-03-13 Thread Boszormenyi Zoltan

2013-03-13 13:45 keltezéssel, Andres Freund írta:

On 2013-03-13 09:09:24 +0100, Boszormenyi Zoltan wrote:

2013-03-13 07:42 keltezéssel, Craig Ringer írta:

On 03/12/2013 06:27 AM, Craig Ringer wrote:

Think also about the case where someone wants to change multiple
values together and having just some set and not others would be
inconsistent.

Yeah, that's a killer. The reload would need to be scheduled for COMMIT
time, it can't be done by `SET PERSISTENT` directly.

Thinking about this some more, I'm not sure this is a good idea.

Right now, SET takes effect immediately. Always, without exception.
Delaying SET PERSISTENT's effects until commit would make it
inconsistent with SET's normal behaviour.

However, *not* delaying it would make it another quirky
not-transactional not-atomic command. That's OK, but if it's not going
to follow transactional semantics it should not be allowed to run within
a transaction, like VACUUM .

Writing the changes immediately but deferring the reload until commit
seems to be the worst of those two worlds.

I was thinking about it a little. There is a hook that runs at the end
of (sub-)transactions. It can be abused for this purpose to make
SET PERSISTENT transactional. The subtransactions can also stack
these settings, by forgetting settings upon ROLLBACK [ TO SAVEPOINT ]
and overwriting previous settings upon COMMIT and RELEASE SAVEPOINT.
All it needs is a list and maintaining intermediate pointers when entering
into a new level of SAVEPOINT. The functions to register such hooks are
in src/include/access/xact.h:

extern void RegisterXactCallback(XactCallback callback, void *arg);
extern void UnregisterXactCallback(XactCallback callback, void *arg);
extern void RegisterSubXactCallback(SubXactCallback callback, void *arg);
extern void UnregisterSubXactCallback(SubXactCallback callback, void *arg);

(sub)xact commit/abort already calls AtEOXact_GUC(commit, nestlevel). So you
wouldn't even need that.


Yes, thanks.


  It seems we could add another value to enum
GucStackState, like GUC_SET_PERSISTENT - and process those only if commit 
nestlevel == 1.


Maybe it's not needed, only enum GucAction needs a new
GUC_ACTION_PERSISTENT value since that's what has any
business in push_old_value(). Adding two new members to
GucStack like these are enough
bool has_persistent;
config_var_value persistent;
and SET PERSISTENT can be treated as GUC_SET. push_old_value()
can merge GUC values set in the same transaction level.


Everytime you see one with commit  nestlevel  1 you put them into them into
the stack one level up.

This seems like its somewhat in line with the way SET LOCAL is implemented?


On the other hand, it would make a lot of sense to implement it
as one setting per file or extending the  code to allow modifying
settings in bulk. The one setting per file should be easier and
it would also allow extensions to drop their settings automatically
into the automatic config directory. I don't know who mentioned
this idea about extensions but it also came up a while back.

I still think one-setting-per-file is the right way to go, yes.

Greetings,

Andres Freund




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-03-06 Thread Boszormenyi Zoltan

2013-03-06 19:53 keltezéssel, Tom Lane írta:

Robert Haas robertmh...@gmail.com writes:

On Wed, Feb 27, 2013 at 8:58 AM, Stephen Frost sfr...@snowman.net wrote:

It's still entirely possible to get 99% done and then hit that last
tuple that you need a lock on and just tip over the lock_timeout_stmt
limit due to prior waiting and ending up wasting a bunch of work, hence
why I'm not entirely sure that this is that much better than
statement_timeout.

I tend to agree that this should be based on the length of any
individual lock wait, not the cumulative duration of lock waits.
Otherwise, it seems like it'll be very hard to set this to a
meaningful value.  For example, if you set this to 1 minute, and that
means the length of any single wait, then you basically know that
it'll only kick in if there is some other, long-running transaction
that's holding the lock.  But if it means the cumulative length of all
waits, it's not so clear, because now you might also have this kick in
if you wait for 100ms on 600 different occasions.  In other words,
complex queries that lock or update many tuples may get killed even if
they never wait very long at all for any single lock.  That seems like
it will be almost indistinguishable from random, unprincipled query
cancellations.

Yeah.  I'm also unconvinced that there's really much use-case territory
here that statement_timeout doesn't cover well enough.  To have a case
that statement-level lock timeout covers and statement_timeout doesn't,
you need to suppose that you know how long the query can realistically
wait for all locks together, but *not* how long it's going to run in the
absence of lock delays.  That seems a bit far-fetched, particularly when
thinking of row-level locks, whose cumulative timeout would presumably
need to scale with the number of rows the query will visit.

If statement-level lock timeouts were cheap to add, that would be one
thing; but given that they're complicating the code materially, I think
we need a more convincing argument for them.


OK, so it's not wanted. Surprise, surprise, it was already dropped
from the patch. Can you _please_ review the last patch and comment
on it instead of the state of past?

Thanks and best regards,
Zoltán Böszörményi



regards, tom lane





--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Matview patch added rewriteDefine.c.orig to the repository

2013-03-04 Thread Boszormenyi Zoltan

2013-03-04 08:02 keltezéssel, Simon Riggs írta:

On 4 March 2013 06:39, Boszormenyi Zoltan z...@cybertec.at wrote:


commit 3bf3ab8c563699138be02f9dc305b7b77a724307
(Add a materialized view relations.) added this:

  src/backend/rewrite/rewriteDefine.c.orig| 945 +...
...
  create mode 100644 src/backend/rewrite/rewriteDefine.c.orig

Committers should be more careful if they want to do work late Sunday.
I know, Monday begins on Saturday[1], but still... ;-)

AFAICS Kevin fixed this last night...



Did he? I just did this:

[zozo@localhost postgresql]$ git branch -a
* master
  remotes/origin/HEAD - origin/master
  remotes/origin/REL2_0B
  remotes/origin/REL6_4
  remotes/origin/REL6_5_PATCHES
  remotes/origin/REL7_0_PATCHES
  remotes/origin/REL7_1_STABLE
  remotes/origin/REL7_2_STABLE
  remotes/origin/REL7_3_STABLE
  remotes/origin/REL7_4_STABLE
  remotes/origin/REL8_0_STABLE
  remotes/origin/REL8_1_STABLE
  remotes/origin/REL8_2_STABLE
  remotes/origin/REL8_3_STABLE
  remotes/origin/REL8_4_STABLE
  remotes/origin/REL8_5_ALPHA1_BRANCH
  remotes/origin/REL8_5_ALPHA2_BRANCH
  remotes/origin/REL8_5_ALPHA3_BRANCH
  remotes/origin/REL9_0_ALPHA4_BRANCH
  remotes/origin/REL9_0_ALPHA5_BRANCH
  remotes/origin/REL9_0_STABLE
  remotes/origin/REL9_1_STABLE
  remotes/origin/REL9_2_STABLE
  remotes/origin/Release_1_0_3
  remotes/origin/WIN32_DEV
  remotes/origin/ecpg_big_bison
  remotes/origin/master
[zozo@localhost postgresql]$ cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote origin]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git://git.postgresql.org/git/postgresql.git
[branch master]
remote = origin
merge = refs/heads/master
[zozo@localhost postgresql]$ git pull origin
Already up-to-date.
[zozo@localhost postgresql]$ find . -name *.orig
./src/backend/rewrite/rewriteDefine.c.orig

The main repo at http://git.postgresql.org/gitweb/?p=postgresql.git;a=summary
only shows one followup commit (just as in my local copy):
bc61878682051678ade5f59da7bfd90ab72ce13b
Fix map_sql_value_to_xml_value() to treat domains like their base types.

In which branch was this fixed?

Thanks,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Matview patch added rewriteDefine.c.orig to the repository

2013-03-04 Thread Boszormenyi Zoltan

2013-03-04 08:10 keltezéssel, Devrim Gündüz írta:

Hi,

Kevin already removed it with a followup commit:

http://git.postgresql.org/pg/commitdiff/d63977eea3ab18fdec05e370b633d10b9fd20179



404 - Unknown commit object




Regards, Devrim

Boszormenyi Zoltan z...@cybertec.at wrote:

Hi,

commit 3bf3ab8c563699138be02f9dc305b7b77a724307
(Add a materialized view relations.) added this:

src/backend/rewrite/rewriteDefine.c.orig| 945 +...
...
create mode 100644 src/backend/rewrite/rewriteDefine.c.orig

Committers should be more careful if they want to do work late Sunday.
I know, Monday begins on Saturday[1], but still... ;-)

[1]http://en.wikipedia.org/wiki/Monday_Begins_on_Saturday

Best regards,
Zoltán Böszörményi


--
Devrim Gündüz 



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



Re: [HACKERS] Matview patch added rewriteDefine.c.orig to the repository

2013-03-04 Thread Boszormenyi Zoltan

2013-03-04 13:01 keltezéssel, Magnus Hagander írta:


The repository is currently broken. There's a thread on www about it, and also see the 
email to hackers a few hours ago telling committers to stop pushing until it's fixed.




Thanks for the info, I didn't know about it. I am not
subscribed to -www and I accidentally skipped your mail, too.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] Matview patch added rewriteDefine.c.orig to the repository

2013-03-03 Thread Boszormenyi Zoltan

Hi,

commit 3bf3ab8c563699138be02f9dc305b7b77a724307
(Add a materialized view relations.) added this:

 src/backend/rewrite/rewriteDefine.c.orig| 945 +...
...
 create mode 100644 src/backend/rewrite/rewriteDefine.c.orig

Committers should be more careful if they want to do work late Sunday.
I know, Monday begins on Saturday[1], but still... ;-)

[1] http://en.wikipedia.org/wiki/Monday_Begins_on_Saturday

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-02-28 Thread Boszormenyi Zoltan

2013-02-27 20:38 keltezéssel, Boszormenyi Zoltan írta:

2013-02-27 20:06 keltezéssel, Stephen Frost írta:

Zoltan,

* Boszormenyi Zoltan (z...@cybertec.at) wrote:

If we get rid of the per-statement variant, there is no need for that either.

For my 2c, I didn't see Tom's comments as saying that we shouldn't have
that capability, just that the implementation was ugly. :)


But I am happy to drop it. ;-)


That said, perhaps we should just drop it for now, get the lock_timeout
piece solid, and then come back to the question about lock_timeout_stmt.


OK, let's do it this way.


Dropped the per-statement lock timeout for now. The patch is
now obviously simpler and shorter. I renamed
enable/disable_multiple_timeouts() to simply enable/disable_timeouts()
since the List* argument implies more than one of them and
you need to type less.

The comments and the documentation needs another review,
to make sure I left no traces of the per-statements variant.
I can't see any but I stared at this patch for so long that I can't
be sure anymore.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/

diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml
index 175d1d5..c124927 100644
--- a/doc/src/sgml/config.sgml
+++ b/doc/src/sgml/config.sgml
@@ -5078,7 +5078,10 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
 milliseconds, starting from the time the command arrives at the server
 from the client.  If varnamelog_min_error_statement/ is set to
 literalERROR/ or lower, the statement that timed out will also be
-logged.  A value of zero (the default) turns this off.
+logged.  The timeout may happen any time, i.e. while waiting for locks
+on database objects or in case of a large result set, during data
+retrieval from the server after all locks were successfully acquired.
+A value of zero (the default) turns this off.
/para
 
para
@@ -5089,6 +5092,33 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
   /listitem
  /varlistentry
 
+ varlistentry id=guc-lock-timeout xreflabel=lock_timeout
+  termvarnamelock_timeout/varname (typeinteger/type)/term
+  indexterm
+   primaryvarnamelock_timeout/ configuration parameter/primary
+  /indexterm
+  listitem
+   para
+Abort any statement which waits longer than the specified number of
+milliseconds while attempting to acquire a lock on rows, pages,
+tables, indices or other objects. The timeout applies to each of
+the locks individually.
+   /para
+   para
+As opposed to varnamestatement_timeout/, this timeout (and the error)
+may only occur while waiting for locks. If varnamelog_min_error_statement/
+is set to literalERROR/ or lower, the statement that timed out will
+also be logged. A value of zero (the default) turns this off.
+   /para
+
+   para
+Setting varnamelock_timeout/ in
+filenamepostgresql.conf/ is not recommended because it
+affects all sessions.
+   /para  
+  /listitem   
+ /varlistentry
+
  varlistentry id=guc-vacuum-freeze-table-age xreflabel=vacuum_freeze_table_age
   termvarnamevacuum_freeze_table_age/varname (typeinteger/type)/term
   indexterm
diff --git a/doc/src/sgml/ref/lock.sgml b/doc/src/sgml/ref/lock.sgml
index 05acbc4..3de08d5 100644
--- a/doc/src/sgml/ref/lock.sgml
+++ b/doc/src/sgml/ref/lock.sgml
@@ -39,10 +39,12 @@ LOCK [ TABLE ] [ ONLY ] replaceable class=PARAMETERname/replaceable [ * ]
literalNOWAIT/literal is specified, commandLOCK
TABLE/command does not wait to acquire the desired lock: if it
cannot be acquired immediately, the command is aborted and an
-   error is emitted.  Once obtained, the lock is held for the
-   remainder of the current transaction.  (There is no commandUNLOCK
-   TABLE/command command; locks are always released at transaction
-   end.)
+   error is emitted. If varnamelock_timeout/varname is set and
+   the lock cannot be acquired under the specified timeout,
+   the command is aborted and an error is emitted. Once obtained,
+   the lock is held for the remainder of the current transaction.
+   (There is no commandUNLOCK TABLE/command command; locks are
+   always released at transaction end.)
   /para
 
   para
diff --git a/doc/src/sgml/ref/select.sgml b/doc/src/sgml/ref/select.sgml
index 0f9d527..0640898 100644
--- a/doc/src/sgml/ref/select.sgml
+++ b/doc/src/sgml/ref/select.sgml
@@ -1309,6 +1309,14 @@ FOR KEY SHARE [ OF replaceable class=parametertable_name/replaceable [, ..
/para
 
para
+If literalNOWAIT/ option is not specified and either
+varnamestatement_timeout/varname or varnamelock_timeout/varname
+is set

Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-02-27 Thread Boszormenyi Zoltan

2013-02-27 04:06 keltezéssel, Stephen Frost írta:

Zoltan,

* Boszormenyi Zoltan (z...@cybertec.at) wrote:

attached is v30, I hope with everything fixed.

Making progress, certainly.

Given the hack to the API of enable_timeout_after() and the need for
timeout_reset_base_time(), I'm just going to voice my objection to the
accumulated wait time on locks portion again.  I still like the idea
of a timeout for waiting on relation-level locks, as we acquire those
all up-front and we'd be able to just set a timeout at the appropriate
point and then release it when we're past acquiring the relation-level
locks.  Seems like that would be much cleaner.


Yes, it would be cleaner. But this way the total timeout the
statement would wait for locks is N * lock_timeout - some delta
in the worst case when all the locks can be acquired just under
the set timeout interval, N being the number of locks that statement
wants to acquire. For some use cases, it's better to have known limit
in the total amount of wait time. But unlike statement_timeout,
with lock_timeout_stmt the statement can still finish after this limit
as it does useful work besides waiting for locks.


On the other hand, if we're going to go down this route, I'm really
starting to wonder if it should be the timeout systems responsibility to
keep track of such accumulated time.


Thinking about it a bit more, I start to agree with it.
It's not likely that any new timeout sources will get added
to proc.c that has anything to do with waiting across multiple locks.
From this POV, this accumulated time can be done by proc.c itself.
But this makes it necessary to reschedule the timer from the
ProcSleep() loop so it increases the number of setitimer() calls.
But with clever coding, the it_interval part of struct itimerval
can be used to decrease the number of setitimer calls, so it may
be balanced out.

Another thought is that there is no need to have an extra function
to set the start time for the timeouts. It can be folded into
enable_timeout_after(), enable_timeout_at() and
enable_multiple_timeouts() and it simplifies the API, too.

Since setitimer() has microsecond resolution, I wonder whether
the timeout.c code shouldn't accept that, too. Especially if we want
to keep the per-statement accumulated version for the lock timeout.
Then time to wait that can be represented using int32 would be
about 35.8 minutes at most, we will need to use int64 if the maximum
number of millisecs is to stay as INT_MAX, which I guess it should.

Comments?


Other than that..


- List based enable/disable_multiple_timeouts()

That looks good, like the use of foreach(), etc, but I don't like how
you've set up delay_ms as a pointer..?  Looks to be to allow you to
initialize the TimeoutParams structs early in proc.c..?  Is there
another reason it needs to be a pointer that I'm missing?  Why not build
the TimeoutParam strcutures in the if() blocks that check if the GUCs
are set..?


It's fixed in my tree and I also added an Assert to
enable_multiple_timeouts() to make sure all timeout sources
use either TIMEOUT_AT or TIMEOUT_AFTER. Some more
comments were also fixed. But I would like to send out the
new  patch after the above questions are settled.

I also want to thank you for your comments. It's good to have
a fresh look on this code.


- separate per-lock and per-statement lock_timeout variants
- modified comments and documentation

Thanks.

Stephen



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-02-27 Thread Boszormenyi Zoltan

2013-02-27 19:07 keltezéssel, Tom Lane írta:

Stephen Frost sfr...@snowman.net writes:

Tom, can you comment on your thoughts around this notion of an aggregate
time constraint for waiting on locks?  As mentioned upthread, I like the
idea of having an upper-limit on waiting for relation-level locks, but
once you're past that, I'm not sure that an aggregate waiting-on-locks
is any better than the overall statement-level timeout and it seems
somewhat messy, to me anyway.

I think anything that makes this patch simpler is a good idea.  I don't
like any of the accum_time stuff: it complicates the timeout API
unreasonably and slows down existing use cases.


Perfect. :-)


Some other thoughts:

* timeout_reset_base_time() seems like an ugly and unnecessary API wart.
I don't like the timeout_start state variable at all; if you need
several timeouts to be scheduled relative to the exact same starting
point, can't you just do that in a single enable_multiple_timeouts()
call?  And I think the optional TMPARAM_ACCUM action is completely
unacceptable,


If we get rid of the per-statement variant, there is no need for that either.


  because it supposes that every user of a timeout, now and
in the future, is okay with having their accumulated time reset at the
same point.  The whole point of having invented this timeout API is to
serve timeout uses we don't currently foresee, so actions that affect
every timeout seem pretty undesirable.

* I don't care for changing the API of enable_timeout_after when there
is in fact not a single caller using the flags argument (probably
because the only defined flag is too baroque to be useful).  If there
were a use case for the accum action it'd be better to have a separate
API function for it, probably.


This way, enable_timeout_after() wouldn't have this extra argument either.

Thanks for your kind words.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-02-27 Thread Boszormenyi Zoltan

2013-02-27 20:06 keltezéssel, Stephen Frost írta:

Zoltan,

* Boszormenyi Zoltan (z...@cybertec.at) wrote:

If we get rid of the per-statement variant, there is no need for that either.

For my 2c, I didn't see Tom's comments as saying that we shouldn't have
that capability, just that the implementation was ugly. :)


But I am happy to drop it. ;-)


That said, perhaps we should just drop it for now, get the lock_timeout
piece solid, and then come back to the question about lock_timeout_stmt.


OK, let's do it this way.



Thanks,

Stephen



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-02-25 Thread Boszormenyi Zoltan

2013-02-24 16:14 keltezéssel, Boszormenyi Zoltan írta:

2013-02-24 15:03 keltezéssel, Stephen Frost írta:

* Boszormenyi Zoltan (z...@cybertec.at) wrote:

2013-02-24 03:23 keltezéssel, Stephen Frost írta:

No, it isn't.  Patches posted to the list should be in context diff
format (and uncompressed unless it's too large) for easier reading.
That avoids having to download it, apply it to a git tree and then
create the diff ourselves.  Indeed, the move to git had impact on this
at all.

I remembered this mail from The Master(tm):
http://www.postgresql.org/message-id/21555.1339866...@sss.pgh.pa.us

Which matches exactly what I was saying- context diff provides easier
readind for review purposes, which is presumably what you were looking
to have happen when you posted this patch to the mailing list. And it's
still the documented expectation and project policy, regardless of any
individual's email.  If we're going to change it, then the
documentation, et al, should be updated as well.

For my 2c, I still prefer context diffs posted to the mailing lists,
but would also like to see more people posting pull requests. That
doesn't make it project policy though.


So, more than halfof the recently posted patches come
directly from git diff. The preference has changed.

No, more people have ignored the project policy than not- that doesn't
say anything about the preference or what the policy is.


lock_timeout_wait and lock_timeout_stmt_wait ?

Hm. How about without the _wait suffix?
Or lock_timeout vs statement_lock_timeout?

I could live without the _wait suffix, but it occurs to me that none of
these really indicate that statement_lock_timeout is an accumulated
timeout.  Perhaps it should say 'total lock wait timeout' or similar?


statement_timeout is the legacy behaviour, it should be kept.
It's behaviour is well understood: the statement finishes under
the specified time or it throws an error. The problem from the
application point of view is that the error can happen while
the tuples are being transferred to the client, so the recordset
can be cut in half.

lock_timeout_stmt (or lock_timeout_option = per_statement)
is somewhat extending the statement_timeout as only the
time waiting on locks are counted, so SELECT FOR UPDATE/etc.
may throw an error but if all rows are collected already, or
plain SELECT is run, the application gets them all.
This seems to follow the Microsoft SQL Server semantics:
http://msdn.microsoft.com/en-us/library/ms189470.aspx

The documentation at that link appears to match what 'lock_timeout'
would do.  Note that it says 'a lock' here: When a wait for a lock
exceeds the time-out value, an error is returned., or have you tested
the actual behavior and seen it treat this value as an accumulated
time across all lock waits for an entire statement?


(Note to myself: don't read with headache.)
I may have misread the MSDN link.




The per-lock lock_timeout was the result of a big Informix
project ported to PostgreSQL, this follows Informix semantics:
http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqls.doc/sqls788.htm 


I agree that the Informix command looks to be per-lock, but based on my
simple reading of both documentation links, I think they're actually the
same behavior and neither is about an accumulated time.


You seem to be right.


Because Timestamp[Tz] is microsecond resolution, and the timeout
GUCs are in milliseconds. Adding up time differences (and rounding
or truncating them to millisecond in the process) would make the
per-statement lock timeout lose precision...

Removing the accumulation-based option would fix that.. :D


To call out the wrath of Tom? No, thanks. :-D
IIRC, he was the one who didn't like the per-lock behaviour
the first time he looked at this patch in an earlier form
back in 2010/2011 and he proposed this use case instead.
If not him, then someone else. I got the idea from this list...


Another question just popped up. Now, that
bool enable_multiple_timeouts(List *timeouts);
exists, do we really need the singular versions?

Since the timeout after N msec have the per-lock and per-stmt
versions, enable_timeout_after() gained a new argument to
distinguish between the two cases and every occurrences of
this function happen to just use 0 here. The only usage of the
per-stmt variant is used with enable_multiple_timeouts().

Wouldn't it be better to have a single
bool enable_timeouts(List *timeouts);
instead?




Best regards,
Zoltán Böszörményi




--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: unified vs context diffs (was Re: [HACKERS] Strange Windows problem, lock_timeout test request)

2013-02-25 Thread Boszormenyi Zoltan

2013-02-25 15:25 keltezéssel, Tom Lane írta:

Stephen Frost sfr...@snowman.net writes:

* Robert Haas (robertmh...@gmail.com) wrote:

True, but I'm with Heikki: it's a pedantic and unhelpful guideline.

Then let's change it, drop the preference, and update the documentation.

I think we should drop the hard requirement for context-format, and
instead say that it must not be plain (context-free) diff, since that
clearly *is* a hard requirement.

However, I liked the upthread suggestion (I think it was from Heikki)
that we recommend that submitters actually take a moment to think about
which format is more readable for their particular patch.   Readability
is important not only to help people who just give the patch a quick
eyeball, but also to help the inevitable situations where hunks have
to be applied by hand because the underlying code has changed.  The
less readable the patch, the more likely an error in doing that.


+1

I think the readability is mostly the de-facto threshold. Considering
that quite a few plain git diff patches were committed during this CF
but those were readable in that format, even biggies like teach
receivexlog to switch timelines which (I just browsed it) had parts
that rewrote code in a way that the diff had pieces with different
indentation intermixed. This can constitute to being unreadable
at times but it also depends on the reader.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-02-24 Thread Boszormenyi Zoltan

2013-02-24 03:23 keltezéssel, Stephen Frost írta:

Zoltán,

* Boszormenyi Zoltan (z...@cybertec.at) wrote:

2013-02-23 02:55 keltezéssel, Stephen Frost írta:

First off, it's not in context diff format, which is the PG standard for
patch submission.

Since moving to GIT, this expectation is obsolete.

No, it isn't.  Patches posted to the list should be in context diff
format (and uncompressed unless it's too large) for easier reading.
That avoids having to download it, apply it to a git tree and then
create the diff ourselves.  Indeed, the move to git had impact on this
at all.


I remembered this mail from The Master(tm):
http://www.postgresql.org/message-id/21555.1339866...@sss.pgh.pa.us




All PG hackers
became comfortable with the unified diff format, see references
from the list. A lot of hackers post git diff patches which cannot
produce context diff, either.

It's quite possible to create a context diff from git- indeed, it's
documented on the http://wiki.postgresql.org/wiki/Working_with_Git
portion of the wiki, specifically to help people understand how to take
the changes they've made in their git forks and create context diffs to
post to the mailing lists.  The preference for context diffs is also
still documented at http://wiki.postgresql.org/wiki/Submitting_a_Patch.

And, to be honest, I'm not sure how familiar you are with the history of
PG in this area, but I've been through all of it from the pre-git CVS
days, through the migration to git, to the exclusive use of git.


I started with Postgres95, though only using the source tarballs.
I started following CVS at around 2003 or so.


   I feel
quite confident that the preference for context diffs hasn't changed.


With stats for the February, 2013:
Name ctx  ctx/gitunif/git unif
Dimitry Fontaine 40   1  0
Ian Lawrence Barwick  0 1   0  0
Alvaro Herrera   10 0   5 0
Pavel Stehule 9 0   0  0
Heikki Linnakangas0 0   7 0
Michael Paquier   0 0   6 0
Andres Freund 0 0   5 0
Alexander Law 0 0   1  0
Etsuro Fujita 0 0   4 0
Amit Kapila   4 0   0  0
Kevin Grittner2 0   3  0
Gurjeet Singh 0 0   20
Erik Rijkers  0 0   0  1
Zoltan Boszormenyi0 0   2  0
Tomas Vondra  0 0   2  0
Bruce Momjian 0 4   0  0
Fujii Masao   1 0   0  0
David Fetter  5 0   0  0
Jonathan Rogers   0 0   1  0
Andrew Dunstan2 0   0  0
Manlio Perillo0 0   1  0
Dean Rasheed  0 1   2  0
Jeff Janes0 2   1  0
Phil Sorber   0 3   2  0
Mark Wong 0 1   0  0
Ivan Lezhnjov IV  0 0   1  0
Kohei Gagai   0 0   2  0
MauMau1 0   0  0
Tom Lane  0 1   0  0
Sean Chittenden   0 0   2  0
Albe Laurenz  0 1   0  0
Daniel Farina 1 0   0  0
Simon Riggs   0 0   3  0
Peter Eisentraut  0 0   4  0

Plain context diffs: 39
Context diffs generated from git: 14
git diff patches: 57
Plain unified diff: 1

Some mails contained more than one patch, these were
counted as-is. One patch is one patch.

So, more than halfof the recently posted patches come
directly from git diff. The preference has changed.
But indeed, plain diff -u is cleanly in the minority.
I can repost my patch from git diff, too, to be in
the majority. :-P


That's not strictly true but it's not widely used either:

$ find . -type f | xargs grep weight | grep heavy
./monitoring.sgml: entryProbe that fires when a request for a
heavyweight lock (lmgr lock)
./monitoring.sgml: entryProbe that fires when a request for a
heavyweight lock (lmgr lock)

Interesting.  That didn't show up in the searches that I was doing
through the web interface, though it does now.  If we're going to use
that term, we should define it in the lock documentation.  If not, then
we should avoid it everywhere.  I'm fine with either.


Me too, the documentation should be consistent. I will remove the
heavyweight term.




- I don't particularly like lock_timeout_option, for a couple of
   reasons.  First is simply the name is terrible, but beyond that, it
   strikes me that wanting to set both a 'per-lock timeout' and a
   'overall waiting-for-locks timeout' at the same time would be a
   reasonable use-case.  If we're going to have 2 GUCs and we're going to
   support each of those options, why not just let the user specify
   values for each?

OK, suggest names for the 2 GUCS, please.

lock_timeout_wait and lock_timeout_stmt_wait ?


Hm. How about without the _wait suffix?
Or lock_timeout vs statement_lock_timeout

Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-02-24 Thread Boszormenyi Zoltan

Stephen,

2013-02-23 02:55 keltezéssel, Stephen Frost írta:

Zoltán,

* Zoltán Böszörményi (z...@cybertec.at) wrote:

The patch now passed make check in both cases.

Is v29 the latest version of this patch..?


attached is v30, I hope with everything fixed.
- List based enable/disable_multiple_timeouts()
- separate per-lock and per-statement lock_timeout variants
- modified comments and documentation

Patch is git diff format. Please, review.

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



2-lock_timeout-v30.patch.gz
Description: Unix tar archive

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-02-24 Thread Boszormenyi Zoltan

2013-02-24 15:03 keltezéssel, Stephen Frost írta:

* Boszormenyi Zoltan (z...@cybertec.at) wrote:

2013-02-24 03:23 keltezéssel, Stephen Frost írta:

No, it isn't.  Patches posted to the list should be in context diff
format (and uncompressed unless it's too large) for easier reading.
That avoids having to download it, apply it to a git tree and then
create the diff ourselves.  Indeed, the move to git had impact on this
at all.

I remembered this mail from The Master(tm):
http://www.postgresql.org/message-id/21555.1339866...@sss.pgh.pa.us

Which matches exactly what I was saying- context diff provides easier
readind for review purposes, which is presumably what you were looking
to have happen when you posted this patch to the mailing list.  And it's
still the documented expectation and project policy, regardless of any
individual's email.  If we're going to change it, then the
documentation, et al, should be updated as well.

For my 2c, I still prefer context diffs posted to the mailing lists,
but would also like to see more people posting pull requests.  That
doesn't make it project policy though.


So, more than halfof the recently posted patches come
directly from git diff. The preference has changed.

No, more people have ignored the project policy than not- that doesn't
say anything about the preference or what the policy is.


lock_timeout_wait and lock_timeout_stmt_wait ?

Hm. How about without the _wait suffix?
Or lock_timeout vs statement_lock_timeout?

I could live without the _wait suffix, but it occurs to me that none of
these really indicate that statement_lock_timeout is an accumulated
timeout.  Perhaps it should say 'total lock wait timeout' or similar?


statement_timeout is the legacy behaviour, it should be kept.
It's behaviour is well understood: the statement finishes under
the specified time or it throws an error. The problem from the
application point of view is that the error can happen while
the tuples are being transferred to the client, so the recordset
can be cut in half.

lock_timeout_stmt (or lock_timeout_option = per_statement)
is somewhat extending the statement_timeout as only the
time waiting on locks are counted, so SELECT FOR UPDATE/etc.
may throw an error but if all rows are collected already, or
plain SELECT is run, the application gets them all.
This seems to follow the Microsoft SQL Server semantics:
http://msdn.microsoft.com/en-us/library/ms189470.aspx

The documentation at that link appears to match what 'lock_timeout'
would do.  Note that it says 'a lock' here: When a wait for a lock
exceeds the time-out value, an error is returned., or have you tested
the actual behavior and seen it treat this value as an accumulated
time across all lock waits for an entire statement?


(Note to myself: don't read with headache.)
I may have misread the MSDN link.




The per-lock lock_timeout was the result of a big Informix
project ported to PostgreSQL, this follows Informix semantics:
http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqls.doc/sqls788.htm

I agree that the Informix command looks to be per-lock, but based on my
simple reading of both documentation links, I think they're actually the
same behavior and neither is about an accumulated time.


You seem to be right.


Because Timestamp[Tz] is microsecond resolution, and the timeout
GUCs are in milliseconds. Adding up time differences (and rounding
or truncating them to millisecond in the process) would make the
per-statement lock timeout lose precision...

Removing the accumulation-based option would fix that.. :D


To call out the wrath of Tom? No, thanks. :-D
IIRC, he was the one who didn't like the per-lock behaviour
the first time he looked at this patch in an earlier form
back in 2010/2011 and he proposed this use case instead.
If not him, then someone else. I got the idea from this list...

Best regards,
Zoltán Böszörményi

--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Strange Windows problem, lock_timeout test request

2013-02-23 Thread Boszormenyi Zoltan

2013-02-23 02:55 keltezéssel, Stephen Frost írta:

Zoltán,

* Zoltán Böszörményi (z...@cybertec.at) wrote:

The patch now passed make check in both cases.

Is v29 the latest version of this patch..?


Yes, is was until you came up with your review... ;-)


Looking through the patch, I've noticed a couple of things:

First off, it's not in context diff format, which is the PG standard for
patch submission.


Since moving to GIT, this expectation is obsolete. All PG hackers
became comfortable with the unified diff format, see references
from the list. A lot of hackers post git diff patches which cannot
produce context diff, either.


   Next, the documentation has a few issues:

- Heavy-weight should really be defined in terms of specific lock
   types or modes.  We don't use the 'heavyweight' term anywhere else in
   the documentation that I've found.


That's not strictly true but it's not widely used either:

$ find . -type f | xargs grep weight | grep heavy
./monitoring.sgml: entryProbe that fires when a request for a heavyweight lock (lmgr 
lock)
./monitoring.sgml: entryProbe that fires when a request for a heavyweight lock (lmgr 
lock)




- I'd reword this:

   Abort any statement that tries to acquire a heavy-weight lock on rows,
   pages, tables, indices or other objects and the lock(s) has to wait
   more than the specified number of milliseconds.

   as:

   Abort any statement which waits longer than the specified number of
   milliseconds while attempting to acquire a lock on ...


OK.



- I don't particularly like lock_timeout_option, for a couple of
   reasons.  First is simply the name is terrible, but beyond that, it
   strikes me that wanting to set both a 'per-lock timeout' and a
   'overall waiting-for-locks timeout' at the same time would be a
   reasonable use-case.  If we're going to have 2 GUCs and we're going to
   support each of those options, why not just let the user specify
   values for each?


OK, suggest names for the 2 GUCS, please.


- This is a bit disingenuous:

   If literalNOWAIT/ option is not specified and
   varnamelock_timeout/varname is set and the lock or statement
   (depending on varnamelock_timeout_option/varname) needs to wait
   more than the specified value in milliseconds, the command reports
   an error after timing out, rather than waiting indefinitely.

   The SELECT would simply continue to wait until the lock is available.
   That's a bit more specific than 'indefinitely'.  Also, we might add a
   sentence about statement_timeout as well, if we're going to document
   what can happen if you don't use NOWAIT with your SELECT-FOR-UPDATE.
   Should we add documentation to the other commands that wait for locks?

- Looks like this was ended mid-thought...:

+ * Lock a semaphore (decrement count), blocking if count would be  0
+ * until a timeout triggers. Returns true if


Right.



- Not a big fan of this:

+* See notes in PGSemaphoreLock.


Why? Copypaste the *long* comment (a different one in each *_sema.c)
or omitting the comments is better? Suggest a better comment, and
it will be included.


- I'm not thrilled with the new API for defining the timeouts.
   Particularly, I believe the more common convention for passing around
   arrays of structures is to have an empty array at the end, which
   avoids having to remember to update the # of entries every time it
   gets changed.  Of course, another option would be to use our existing
   linked list implementation and its helper macros such as our
   foreach() construct.


A linked list might be better, actually I like it.


- As I've mentioned in other places/times, comments should be about why
   we're doing something, not what we're doing- the code tells you that.
   As such, comments like this really aren't great:
   /* Assert request is sane */
   /* Now re-enable the timer, if necessary. */

- Do we really need TimestampTzPlusMicroseconds..?


Well, my code is the only user for this macro but it's cleaner
than explicitly doing

#ifdef HAVE_INT64_TIMESTAMP
fin_time = timeout_start + delay_ms * (int64)1000;
#else
fin_time = timeout_start + delay_ms / 100.0;
#endif



In general, I like this feature and a number of things above are pretty
small issues.  The main questions, imv, are if we really need both
'options', and, if so, how they should work, and the API for defining
timers.

Thanks,

Stephen



--
--
Zoltán Böszörményi
Cybertec Schönig  Schönig GmbH
Gröhrmühlgasse 26
A-2700 Wiener Neustadt, Austria
Web: http://www.postgresql-support.de
 http://www.postgresql.at/



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


  1   2   3   4   5   >