Re: Query execution in Perl TAP tests needs work

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Query execution in Perl TAP tests needs work
Date: 2023-09-02 18:42:42
Message-ID: 05341dc0-a5c3-f631-35e3-54235cfed774@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 2023-08-30 We 21:29, Thomas Munro wrote:
> On Thu, Aug 31, 2023 at 10:32 AM Andrew Dunstan<andrew(at)dunslane(dot)net> wrote:
>> #!/usr/bin/perl
>>
>> use strict; use warnings;
>>
>> use FFI::Platypus;
>>
>> my $ffi = FFI::Platypus->new(api=>1);
>> $ffi->lib("inst/lib/libpq.so");
>>
>>
>> $ffi->type('opaque' => 'PGconn');
>> $ffi->attach(PQconnectdb => [ 'string' ] => 'PGconn');
>> $ffi->attach(PQfinish => [ 'PGconn' ] => 'void');
>>
>> $ffi->type('opaque' => 'PGresult');
>> $ffi->attach(PQexec => [ 'PGconn', 'string' ] => 'PGresult');
>> $ffi->attach(PQgetvalue => [ 'PGresult', 'int', 'int' ] => 'string');
>>
>> my $pgconn = PQconnectdb("dbname=postgres host=/tmp");
>> my $res = PQexec($pgconn, "select count(*) from pg_class");
>> my $count = PQgetvalue( $res, 0, 0);
>>
>> print "count: $count\n";
>>
>> PQfinish($pgconn);
> It looks very promising so far. How hard would it be for us to add
> this dependency? Mostly pinging build farm owners?
>
> I'm still on the fence, but the more I know about IPC::Run, the better
> the various let's-connect-directly-from-Perl options sound...

Here's some progress. I have put it all in a perl module, which I have
tested on Windows (both mingw and MSVC) as well as Ubuntu. I think this
is probably something worth having in itself. I wrapped a substantial
portion of libpq, but left out things to do with large objects, async
processing, pipelining, SSL and some other things. We can fill in the
gaps in due course.

The test program now looks like this:

use strict;
use warnings;

use lib ".";
use PqFFI;

PqFFI::setup("inst/lib");

my $conn = PQconnectdb("dbname=postgres host=/tmp");
my $res = PQexec($conn, 'select count(*) from pg_class');
my $count = PQgetvalue($res,0,0);
print "$count rows in pg_class\n";
PQfinish($conn);

I guess the next thing would be to test it on a few more platforms and
also to see if we need to expand the coverage of libpq for the intended
uses.

I confess I'm a little reluctant to impose this burden on buildfarm
owners. We should think about some sort of fallback in case this isn't
supported on some platform, either due to technological barriers or
buildfarm owner reluctance.

cheers

andrew

--
Andrew Dunstan
EDB:https://www.enterprisedb.com

Attachment Content-Type Size
PqFFI.pm application/x-perl 12.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2023-09-02 18:55:21 Re: Inefficiency in parallel pg_restore with many tables
Previous Message Erik Rijkers 2023-09-02 18:04:02 Re: Row pattern recognition