Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sUv2v-006ezg-Oq for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jul 2024 21:21:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sUv2t-006Giu-SK for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jul 2024 21:21:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sUv2t-006Gij-Ik for pgsql-hackers@lists.postgresql.org; Fri, 19 Jul 2024 21:21:43 +0000 Received: from mail-il1-x12f.google.com ([2607:f8b0:4864:20::12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sUv2q-000R67-K2 for pgsql-hackers@postgresql.org; Fri, 19 Jul 2024 21:21:42 +0000 Received: by mail-il1-x12f.google.com with SMTP id e9e14a558f8ab-3992195d08aso575675ab.0 for ; Fri, 19 Jul 2024 14:21:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721424100; x=1722028900; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=EfH+RurXSE8W1msEg3CzEDewYW8bx3Y2ajnap2xJbAM=; b=E1B3gYuPNpmIQIMUqBaGAKGkpc4MnBXROIiz40wo8KCMp3eMYjYtzFUNSjbz0UFS1K W1oJCqX/ed/Bj71Nc1SDMWQsP37SccqTcfZfv2fn4Z/7RRoDkTH8lwxcFUiFO66m8CQO IzZu5dYP9GaMJqv8bIWjSMAVRXYZj6phYD0NIn6cLnxVoiN8/ZYt3/p2cr2F3k4dEWvH z5bHgpWAIDneBCWSarYbn2VDoTORFDtZSjjuv7OtU2v25XuiZRkTprnIVEPIg981JpYw E3RBerq9yr5PWRj2Svpnxy98beDk6NGoG4wKi4hGOf+pLCaMNq9sXO4itGF7kTfhaVvW KXAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721424100; x=1722028900; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EfH+RurXSE8W1msEg3CzEDewYW8bx3Y2ajnap2xJbAM=; b=RlQilL3y1Mu1TDsEcSFCZVzVLR8YTI2fiervV3mvTdlVKyJzs3Kt4LRWTW33HdP1Hw nwrGAeYfuhaKRCGA7JQ+v5NgyJZyQiAEXFwXiOzNV0Hmr8RgHfcR+W1pPytHSo24lKDy uVRcvIQM+98Xa0Qua8QCEbTn5D+JKxdoibHRYKJo3NXkcuC3bscBoV1nZhIc67SaH/If KnGmfN/WdyCLJjlRf7jXvSc76Io/WCe69vhZrHAiAkdO0UH9jbyr7RvfKB+IEfd9H2aO EdQD/ESJr0TTmPALk87n63UG56q6MENiq0+vbVNSFIaPv0G+0NPj5qqZ8EVEJCPsW6yW E6Ew== X-Forwarded-Encrypted: i=1; AJvYcCWYNEzrz1rRBrbI2jU3XLn5jf6zHKnGNn5zBVz2eGBrbdLkVaBOrQkFJbGL979G9fDdVxFTL1sqbkHsPREQa/QVU0OvwGo9pd2gbnMC X-Gm-Message-State: AOJu0YxpyXi9rjrGHe4Tx8G4naXDfG5wgRdZsZXmD1pKZbwGXJ8e4D+e RHqtyXXcmY7FtM7W5HuiFcbNsTL5bLHXK55aGAn4PqhkYb0SSzBGQHnHZw== X-Google-Smtp-Source: AGHT+IF5H5j9PCzhReT22hwl4IUwJecClBTTOJs34vl+Fhr1v3yth+JtbaS9gCjxWFDu6CEOXtIQSw== X-Received: by 2002:a05:6e02:1aaf:b0:397:9285:b1ef with SMTP id e9e14a558f8ab-3979285b4f0mr47648735ab.29.1721424099830; Fri, 19 Jul 2024 14:21:39 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-397f5097d71sm6823945ab.13.2024.07.19.14.21.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jul 2024 14:21:39 -0700 (PDT) Date: Fri, 19 Jul 2024 16:21:37 -0500 From: Nathan Bossart To: Daniel Gustafsson Cc: Robert Haas , Jeff Davis , PostgreSQL Hackers Subject: Re: optimizing pg_upgrade's once-in-each-database steps Message-ID: References: <3b97ab8e295ec3db22baa2dfdd49073449ae1696.camel@j-davis.com> <20240517012408.GA1691322@nathanxps13> <26742670-9539-4F30-B6FA-9C1DB743BC23@yesql.se> <4493D323-9726-48F7-A702-E71FB991F76B@yesql.se> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4493D323-9726-48F7-A702-E71FB991F76B@yesql.se> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jul 18, 2024 at 09:57:23AM +0200, Daniel Gustafsson wrote: >> On 17 Jul 2024, at 23:32, Nathan Bossart wrote: >> On Wed, Jul 17, 2024 at 11:16:59PM +0200, Daniel Gustafsson wrote: > >>> +static void >>> +dispatch_query(const ClusterInfo *cluster, AsyncSlot *slot, >>> .... >>> + pg_free(query); >>> +} >>> >>> A minor point, perhaps fueled by me not having played around much with this >>> patchset. It seems a bit odd that dispatch_query is responsible for freeing >>> the query from the get_query callback. I would have expected the output from >>> AsyncTaskGetQueryCB to be stored in AsyncTask and released by async_task_free. >> >> I don't see any problem with doing it the way you suggest. Actually, I do see a problem. If we do it this way, we'll have to store a string per database somewhere, which seems unnecessary. However, while looking into this, I noticed that only one get_query callback (get_db_subscription_count()) actually customizes the generated query using information in the provided DbInfo. AFAICT we can do this particular step without running a query in each database, as I mentioned elsewhere [0]. That should speed things up a bit and allow us to simplify the AsyncTask code. With that, if we are willing to assume that a given get_query callback will generate the same string for all databases (and I think we should), we can run the callback once and save the string in the step for dispatch_query() to use. This would look more like what you suggested in the quoted text. [0] https://postgr.es/m/ZprQJv_TxccN3tkr%40nathan -- nathan