Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jC9Ny-0006Zu-35 for pgsql-performance@arkaria.postgresql.org; Wed, 11 Mar 2020 21:59:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jC9Nx-0000XV-02 for pgsql-performance@arkaria.postgresql.org; Wed, 11 Mar 2020 21:59:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jC9Nw-0000XN-Je for pgsql-performance@lists.postgresql.org; Wed, 11 Mar 2020 21:59:28 +0000 Received: from mail-yw1-xc2c.google.com ([2607:f8b0:4864:20::c2c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jC9Nt-0007pj-O7 for pgsql-performance@postgresql.org; Wed, 11 Mar 2020 21:59:28 +0000 Received: by mail-yw1-xc2c.google.com with SMTP id c15so3590787ywn.7 for ; Wed, 11 Mar 2020 14:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=qjXRjZOB6A1JYuAd87v47tTpSm9Y76BQvV6e1v9HgRg=; b=T9rCN5iF8JncWyxgAVzZBNqtlIq4cD++Q2TuHmY/FfHDA4dNLFHFLBkjlZPhsLZx8X wN0S6MR1KVtcUB2qfTiLlf46c6UtXVhqg809XcdhruGiyFC8ZuBdU1e3lMI4SL1pSmb3 U+BFlbwcWHc+PyBGNYUW4WdDzxNOkw7y+qsGcSouw7q28ceulvBJhOreZ8wTVKYT5k3T wwasQkiTxjSVPmwwrV7hKD1BdnlB41ig2z2x+ZWJt1l2ha/qCZj2yYAhnYc2xY/v4l6A XaKIBE1vF0jScmVxj0pu+RpQTwl64jtl2QOcV69XIPLXR7S/ysLG630irvMX3vmzM1XO sPMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=qjXRjZOB6A1JYuAd87v47tTpSm9Y76BQvV6e1v9HgRg=; b=JcIioNbZUgeDzQRVua84gtFRgDXyKkL6c0wnSv1IRxHs2uch3COFbnU8wtWIWDk9K2 bf9VG79ICd7ueRr+IeWf3jOn/i5YadacG0XFkc2rC40WdWI5QxWup/lCQbjJheeimKvC 1E36ig5C9rZAE4BLHksLr/yQAduN9/CA9GjigL9IEEA11TD14qUgiYlmt5P+hboGBL1A ZheDecUJUBQ0ZxHYe9QxIDgYreaaCS026f/CGKJv03OuCYixfNBVtmiCNqgEbatLwVgv bN1cCZNlGj+vROSxz7B90xmYX4tkI1o/diCo9dpnYuyqFGlVww4c9jqw9TAyRjNRYSEg 3F+Q== X-Gm-Message-State: ANhLgQ3GBfYQKqxVBYu1Tuudi50nwKlzdHjmW35tmKcOSMHIuHHpWokw TKL/N7rN4tZZOkcarNpyVh6EYQ== X-Google-Smtp-Source: ADFU+vvdZDsc6K+bX9kqp2hx/AmCn2mOliivzM8jsA1MSoqd2r4j1dK+uVidGSN0FxOXJUqGQLXzbA== X-Received: by 2002:a25:7383:: with SMTP id o125mr5709104ybc.478.1583963964032; Wed, 11 Mar 2020 14:59:24 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id z14sm5643524ywc.1.2020.03.11.14.59.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Mar 2020 14:59:23 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id CAC098007F2; Wed, 11 Mar 2020 16:59:21 -0500 (CDT) Date: Wed, 11 Mar 2020 16:59:21 -0500 From: Justin Pryzby To: Richard Michael Cc: pgsql-performance@postgresql.org Subject: Re: Slow ext'd query via client native implementation vs. libpq & simple psql Message-ID: <20200311215921.GZ29065@telsasoft.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Mar 11, 2020 at 03:31:48PM -0400, Richard Michael wrote: > The query is trivial: `SELECT [cols] FROM t WHERE id = X` on a 65K row > table. > The Elixir client executes this as an extended query in >500-700ms, very > slow. > If relevant, the client does not use libpq, it is a native implementation. > A simple query via psql `PREPARE q AS ... ; EXECUTE q;` executes in ~130ms. > (Aside, please let me know if psql can execute extended queries.) > To compare another extended query protocol client, I wrote a tiny C program > using libpq PQprepare()/PQexecPrepared() executes in ~100ms. psql can't do it, but pygres can do it since last year. > Would wireshark on client messages reveal anything postgres can't log? I think maybe, like how many round trips there are. Does the difference between the clients scale linearly with the number of rows returned? > Elixir/postgrex extended query: (always >500ms) > ------------------------------- > 2020-03-11 13:46:20.658 EDT [3401] LOG: duration: 513.792 ms plan: ... > Seq Scan on public.genes g0 (cost=0.00..6591.62 rows=60632 width=224) > (actual time=0.523..33.229 rows=60623 loops=1) You can see the "actual time" is low (that's postgres running the query), so the rest seems to comes from something like sending data back to the client or the client parsing the results. -- Justin