Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1luIzP-0006su-Ej for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Jun 2021 18:13:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1luIzO-0001Od-Fn for pgsql-hackers@arkaria.postgresql.org; Fri, 18 Jun 2021 18:13:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1luITI-0008L1-Pu for pgsql-hackers@lists.postgresql.org; Fri, 18 Jun 2021 17:40:00 +0000 Received: from mail-qt1-x82a.google.com ([2607:f8b0:4864:20::82a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1luITD-00083b-OU for pgsql-hackers@lists.postgresql.org; Fri, 18 Jun 2021 17:39:59 +0000 Received: by mail-qt1-x82a.google.com with SMTP id w26so2843090qto.13 for ; Fri, 18 Jun 2021 10:39:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=CYjBoBZ8zv9CoDgS6KBzbI++n8DfkF1PLln4MOWku4c=; b=IcTRsFoCSFa5HG6WyK9c7QHkOkg3vnciRd5iFggP1D+wTWI/Ms8sHs1MiSPe26oxRc 7Ib1R0+BnZZ1nLRHoPR3q4Bgsa9ao71pdmEnQu3U9SGUUNkGXdieLacAy2x+StmjqEUo tkx0kSukScNOp3U1gPOg0l30KCnQ2GopV2x0MfCGbVxsliF9d2d2GfFDxI70k0z5Dvjh Jn8b1RM7iiwQqrEYrNBeaRh8E+f8QCpj47JbxivlY7pv2PLApvqwQc1SadeVAciPWo/H /vg6OvugCHAcQ2RRrzZYUAZPmqawykj4DgQNjF8/GpHKZpcAXbDobRZ3ztuU8LRJxgX4 Mvlg== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=CYjBoBZ8zv9CoDgS6KBzbI++n8DfkF1PLln4MOWku4c=; b=UviDKjri3+pyf6qZZMgUkeRvDtQJqvmkPhhERM7YXtGKZrM1yCFWGkNolfN3Qf5o0p aoK3OY5YihJSjfVA5l4jCsjqBI+U/WMiKR67ALgBJ9C87pEgxl2H6hjjAaacQNgu3mEh f9J4x6Gzwohu4c6+eWSmJeql87BlVGM6m8PDCkH8xI0hdGW7VmfSyEUc8ikMdMQdpbV4 z47W3kqo9840q5u5xNWVGp7C7JdRsbp15e8u+J+fxGDooJLNUYZ6TEFPKtgPZkAGQWPg 0k23ZrPh6UafzsvgfHMDqHdppt1XVvcF30C1VHnivG+fKXqreWqrS2vLH9BOPrf0P//Q A70Q== X-Gm-Message-State: AOAM533QfDzZc/B8bweRxqIG65IpIeQAKhZTdxG0J9N96TjDP5/Jcvm2 EGStJDfQ9XYDSEuHnXTwIwQtTA== X-Google-Smtp-Source: ABdhPJyUMRyfIZ5nQel05A0iJ1/Vx2yUxma03DXQCz/0NMdESeKzc5cM1NTSfiwlLKbTgEWQ4vQLQQ== X-Received: by 2002:ac8:5e46:: with SMTP id i6mr11672108qtx.366.1624037994785; Fri, 18 Jun 2021 10:39:54 -0700 (PDT) Received: from perhan.alvh.no-ip.org ([190.95.19.95]) by smtp.gmail.com with ESMTPSA id g2sm5826667qtb.63.2021.06.18.10.39.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 10:39:54 -0700 (PDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 605D32A0ADA; Fri, 18 Jun 2021 13:39:52 -0400 (-04) Date: Fri, 18 Jun 2021 13:39:52 -0400 From: Alvaro Herrera To: Boris Kolpackov Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Pipeline mode and PQpipelineSync() Message-ID: <202106181739.7krtfdwkjbic@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Jun-16, Boris Kolpackov wrote: > Specifically, the documentation[1] > makes it sound like the use of PQpipelineSync() is optional (34.5.1.1 > "Issuing Queries"): Hmm. My intention here was to indicate that you should have PQpipelineSync *somewhere*, but that the server was free to start executing some commands even before that, if the buffered commands happened to reach the server somehow -- but not necessarily that the results from those commands would reach the client immediately. I'll experiment a bit more to be sure that what I'm saying is correct. But if it is, then I think the documentation you quote is misleading: > "After entering pipeline mode, the application dispatches requests using > PQsendQuery, PQsendQueryParams, or its prepared-query sibling > PQsendQueryPrepared. These requests are queued on the client-side until > flushed to the server; this occurs when PQpipelineSync is used to establish a > synchronization point in the pipeline, or when PQflush is called. [...] > > The server executes statements, and returns results, in the order the client > sends them. The server will begin executing the commands in the pipeline > immediately, not waiting for the end of the pipeline. [...]" ... because it'll lead people to do what you've done, only to discover that it doesn't really work. I think I should rephrase this to say that PQpipelineSync() is needed where the user needs the server to start executing commands; and separately indicate that it is possible (but not promised) that the server would start executing commands ahead of time because $reasons. Do I have it right that other than this documentation problem, you've been able to use pipeline mode successfully? > So to me it looks like, contrary to the documentation, the server does > not start executing the statements immediately, instead waiting for the > synchronization point. Or am I missing something here? I don't think you are. > The above tests were performed using libpq from 14beta1 running against > PostgreSQL server version 9.5. If you would like to take a look at the > actual code, you can find it here[2] (the PIPELINE_SYNC macro controls > whether PQpipelineSync() is used). Thanks. > On a related note, I've been using libpq_pipeline.c[3] as a reference > and I believe it has a busy loop calling PQflush() repeatedly on line > 721 since once everything has been sent and we are waiting for the > result, select() will keep returning with an indication that the socket > is writable Oops, thanks, will look at fixing this too. > (you can find one way to fix this in [2]). > [2] https://git.codesynthesis.com/cgit/odb/libodb-pgsql/tree/odb/pgsql/statement.cxx?h=bulk#n771 Neat, can do likewise I suppose. -- Álvaro Herrera 39°49'30"S 73°17'W