Redux: Fix hangup of execution of queries like "COPY TO STDOUT" in asynchronous mode (now with tests)#163
Redux: Fix hangup of execution of queries like "COPY TO STDOUT" in asynchronous mode (now with tests)#163esabol wants to merge 1 commit intobucardo:masterfrom
Conversation
|
Yes, it should return 0 |
|
Thanks for adding the tests. I tried adding them myself, but haven't had any success yet. pg_result returns the number of affected rows, just like do. When executing async copy, we don't know the number of affected rows, so the call returns -1. This behavior is similar to the do method: |
|
@true-alex : Sure, that makes sense while |
|
I think I just realized the title of the pull request was wrong? I just changed "COPY TO STDIN" to "COPY TO STDOUT". |
|
Chiming in on the return value question. After tracing through the code, I think Synchronous COPY already returns When you run COPY synchronously, # Synchronous — returns -1
my $ret = $dbh->do("COPY mytable TO STDOUT");
# $ret is -1If # Async — would return 0 (inconsistent)
$dbh->do("COPY mytable TO STDOUT", {pg_async => PG_ASYNC});
# ... pg_ready() ...
my $ret = $dbh->pg_result();
# $ret would be 0, but sync do() returns -1 for the same statement?
DBI defines The code is already consistent
Suggested test fix The TODO test should just assert is ($res, -1, "pg_result() after async COPY TO STDOUT returns -1 (rows unknown during COPY)"); |
|
Thanks for your thoughts on this, @jjn1056. I found your points persuasive, especially this:
What do you think, @turnstep ? |
|
Yeah, that makes sense now that we see it all in context.
|
This is a redux GitHub PR bucardo#101 by true-alex, rebased and with test cases added. See GitHub issue bucardo#98.
a368147 to
5eb1d23
Compare
|
OK, I have rebased and squashed commits. CI pass is clean. Ready for review. @turnstep : Let me know if you want any changes to the tests. |
This is an updated version of @true-alex's pull request #101. It is meant to address issue #98.
$dbh->do("COPY (select * from unnest(ARRAY[1,2,3,4,5,6,7,8]::int[]) as mytable(a)) TO STDOUT", {pg_async => PG_ASYNC});still hangs with DBD::Pg 3.19.0.I have applied @true-alex's proposed fix to the latest master branch and added tests to
t/08async.t.The proposed fix indeed prevents hanging the process, but I don't think the return value of
$dbh->pg_result()is correct. Once$dbh->pg_readybecomes true after executing$dbh->do("COPY (select * from unnest(ARRAY[1,2,3,4,5,6,7,8]::int[]) as mytable(a)) TO STDOUT", {pg_async => PG_ASYNC});,$dbh->pg_result()currently returns -1, but I think it should return 0 (the number of rows affected). Am I right about that, @turnstep ?Marking PR as a draft for now.