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 1qBVKh-0007Zj-9M for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jun 2023 06:59:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qBVKg-0005Fp-4z for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jun 2023 06:59:18 +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 1qBVKf-0005FM-N9 for pgsql-hackers@lists.postgresql.org; Tue, 20 Jun 2023 06:59:17 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qBVKc-003C8E-Hy for pgsql-hackers@postgresql.org; Tue, 20 Jun 2023 06:59:16 +0000 Received: from mail.postgrespro.ru (webmail.mstn.postgrespro.ru [192.168.2.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.pyhalov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id BD5CDE20C31; Tue, 20 Jun 2023 09:59:11 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1687244351; bh=4Gof4KLY2afXm7ysDZFrdhSph49G0wXDFV7hKvdNW5g=; h=Date:From:To:Cc:Subject:In-Reply-To:References:User-Agent: Message-ID:From; b=n6A30iQzvFGDuVeAo/WlzbTuAMHH4kvgetxhcFniCTNhk+x0V32zzvC8NryggPo5E fYPdjZvXnbBi+KObY1pbn3EySx33wSa6bSfjK47/a90L+lyqy315FilR0f+OLx9MVM Dnn7/f0D5ZrGkg8dUmqqEbyZELoHZ0C8jh7uauSzU22KeOus8m/bXQan0MqE8XNz+j 3Q7i2Q2oGISj+Q+5yLcDb5uMjcp+laZheDOLyyob7kOBdgxocVBfKW97siVPJgyKBZ rbG9FxHj/eZHFDfxVESU6TF60AIeG7e6GSb6Gg1ACP7QwXQUOnjB1CqtHHALJA1iwb WRERjn1E0tkRw== MIME-Version: 1.0 Date: Tue, 20 Jun 2023 09:59:11 +0300 From: Alexander Pyhalov To: Bruce Momjian Cc: "Fujii.Yuki@df.MitsubishiElectric.co.jp" , PostgreSQL-development , Andres Freund , Tom Lane , Tomas Vondra , Julien Rouhaud , Daniel Gustafsson , Ilya Gladyshev Subject: Re: Partial aggregates pushdown In-Reply-To: References: <8ffedecae0d21a3cd93805baf1dcc0de@postgrespro.ru> User-Agent: Roundcube Webmail/1.4.11 Message-ID: X-Sender: a.pyhalov@postgrespro.ru Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Bruce Momjian писал 2023-06-20 03:42: > Apologies for the delay in my reply to this email. I looked into the > existing code and I found three things: > > 1) PQserverVersion() just pulls the conn->sversion value from the > existing connection because pqSaveParameterStatus() pulls the > server_version sent by the backend; no need to issue SELECT version(). > > 2) postgres_fdw already has nine calls to GetConnection(), and only > opens a connection if it already doesn't have one. Here is an example: > > /* Get the remote estimate */ > conn = GetConnection(fpinfo->user, false, NULL); > get_remote_estimate(sql.data, conn, &rows, &width, > &startup_cost, &total_cost); > ReleaseConnection(conn); > > Therefore, it seems like it would be near-zero cost to just call conn = > GetConnection() and then PQserverVersion(conn), and > ReleaseConnection(). > You can then use the return value of PQserverVersion() to determine if > you can push down partial aggregates. > Hi. Currently we don't get remote connection while planning if use_remote_estimate is not set. Such change would require to get remote connection in planner, not in executor. This can lead to change of behavior (like errors in explain when user mapping is wrong - e.g. bad password is specified). Also this potentially can lead to establishing connections even when plan node is not actually used (like extreme example - select sum(score) from t limit 0). I'm not saying we shouldn't do it - just hint at possible consequences. -- Best regards, Alexander Pyhalov, Postgres Professional