This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository 
https://gitbox.apache.org/repos/asf/arrow-flight-sql-postgresql.git


The following commit(s) were added to refs/heads/main by this push:
     new 0176b4c  Add COPY benchmark (#152)
0176b4c is described below

commit 0176b4c9831cdb25bb06b51132f33a9ae6ab23d4
Author: Sutou Kouhei <k...@clear-code.com>
AuthorDate: Sat Oct 28 17:33:44 2023 +0900

    Add COPY benchmark (#152)
    
    Closes GH-151
---
 benchmark/integer/{select.c => copy.c} | 32 +++++++++++++++++++-------------
 benchmark/integer/meson.build          |  1 +
 benchmark/integer/select.c             |  4 ++--
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/benchmark/integer/select.c b/benchmark/integer/copy.c
similarity index 70%
copy from benchmark/integer/select.c
copy to benchmark/integer/copy.c
index 4cca75d..9a1ca04 100644
--- a/benchmark/integer/select.c
+++ b/benchmark/integer/copy.c
@@ -17,6 +17,7 @@
  * under the License.
  */
 
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/time.h>
@@ -30,36 +31,41 @@ main(int argc, char** argv)
        PGresult* result;
        struct timeval before;
        struct timeval after;
-       int nFields;
-       int iField;
-       int nTuples;
-       int iTuple;
 
        if (PQstatus(connection) != CONNECTION_OK)
        {
-               fprintf(stderr, "failed to connect: %s", 
PQerrorMessage(connection));
+               fprintf(stderr, "failed to connect: %s\n", 
PQerrorMessage(connection));
                PQfinish(connection);
                return EXIT_FAILURE;
        }
 
        gettimeofday(&before, NULL);
-       result = PQexec(connection, "SELECT * FROM data");
-       if (PQresultStatus(result) != PGRES_TUPLES_OK)
+       result = PQexec(connection, "COPY data TO STDOUT (FORMAT binary)");
+       if (PQresultStatus(result) != PGRES_COPY_OUT)
        {
-               fprintf(stderr, "failed to select: %s", 
PQerrorMessage(connection));
+               fprintf(stderr, "failed to copy: %s\n", 
PQerrorMessage(connection));
                PQclear(result);
                PQfinish(connection);
                return EXIT_FAILURE;
        }
 
-       nTuples = PQntuples(result);
-       nFields = PQnfields(result);
-       for (iTuple = 0; iTuple < nTuples; iTuple++)
+       while (true)
        {
-               for (iField = 0; iField < nFields; iField++)
+               char* buffer;
+               int size = PQgetCopyData(connection, &buffer, 0);
+               if (size == -1)
                {
-                       PQgetvalue(result, iTuple, iField);
+                       break;
                }
+               if (size == -2)
+               {
+                       fprintf(stderr, "failed to read copy data: %s\n", 
PQerrorMessage(connection));
+                       PQclear(result);
+                       PQfinish(connection);
+                       return EXIT_FAILURE;
+               }
+               /* printf("%.*s\n", size, buffer); */
+               free(buffer);
        }
        gettimeofday(&after, NULL);
        printf("%.3fsec\n",
diff --git a/benchmark/integer/meson.build b/benchmark/integer/meson.build
index 93561b2..4bfdea4 100644
--- a/benchmark/integer/meson.build
+++ b/benchmark/integer/meson.build
@@ -16,4 +16,5 @@
 # under the License.
 
 libpq = dependency('libpq')
+executable('copy', 'copy.c', dependencies: [libpq])
 executable('select', 'select.c', dependencies: [libpq])
diff --git a/benchmark/integer/select.c b/benchmark/integer/select.c
index 4cca75d..bf3ad9d 100644
--- a/benchmark/integer/select.c
+++ b/benchmark/integer/select.c
@@ -37,7 +37,7 @@ main(int argc, char** argv)
 
        if (PQstatus(connection) != CONNECTION_OK)
        {
-               fprintf(stderr, "failed to connect: %s", 
PQerrorMessage(connection));
+               fprintf(stderr, "failed to connect: %s\n", 
PQerrorMessage(connection));
                PQfinish(connection);
                return EXIT_FAILURE;
        }
@@ -46,7 +46,7 @@ main(int argc, char** argv)
        result = PQexec(connection, "SELECT * FROM data");
        if (PQresultStatus(result) != PGRES_TUPLES_OK)
        {
-               fprintf(stderr, "failed to select: %s", 
PQerrorMessage(connection));
+               fprintf(stderr, "failed to select: %s\n", 
PQerrorMessage(connection));
                PQclear(result);
                PQfinish(connection);
                return EXIT_FAILURE;

Reply via email to