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 1tqcpj-007wFw-HM for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Mar 2025 18:54:07 +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 1tqcpi-00Ew79-4i for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Mar 2025 18:54:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tqcph-00Ew6z-Ol for pgsql-hackers@lists.postgresql.org; Fri, 07 Mar 2025 18:54:05 +0000 Received: from fhigh-a5-smtp.messagingengine.com ([103.168.172.156]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tqcpd-001Y7F-2R; Fri, 07 Mar 2025 18:54:05 +0000 Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7105F1140110; Fri, 7 Mar 2025 13:54:01 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Fri, 07 Mar 2025 13:54:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1741373641; x=1741460041; bh=S a6U4mSBij1DC5gzKPfaL8L1rFy2du9IkvhdMnMfvDI=; b=gMhFY5nn9ZPdlxJK3 5fAQXydo8YQillIA6qlXKjjpz67oZRh8n3k5goedgFLmLGYOZZwBI1KOlu/4V55C Dogq/Sq49FuUUXunHm6RCG8igWlvHQa2UoV+J/3wXfv1eg+JkHJabjGkboyGJQUR fvyQC+TWQd+yI7+4Ksytb/E6GnVIx9XuVDlyMXELG8gBQM37dkwQReSIHgDDjMv8 92N5E9/mGGb+srCSVEATOAydlbxXS3orYaNaUwwy6/1rpcnM1z2YN49VWfwMsZXR F25NHqmWXBxJMWncKQhiw6+ddE0xCg/NF+tL9bXRmgwjzU58Gajr05g8Os6rQj4E /clzQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduuddugeefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesthekredttddt jeenucfhrhhomheplmhlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlh hvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepuedtgfffvdevhffggefh veejvdehteetleeglefhudduudduveeiheetgeduiefgnecuffhomhgrihhnpehpohhsth hgrhdrvghspdgvnhhtvghrphhrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnoh dqihhprdhorhhgpdhnsggprhgtphhtthhopeehpdhmohguvgepshhmthhpohhuthdprhgt phhtthhopehorhhlohhvmhhgsehgmhgrihhlrdgtohhmpdhrtghpthhtoheprhgrnhhivg hrrdhvfhesghhmrghilhdrtghomhdprhgtphhtthhopehsrdguvghrvghvhigrnhhkohes phhoshhtghhrvghsphhrohdrrhhupdhrtghpthhtoheprghkohhrohhtkhhovhesphhosh htghhrvghsqhhlrdhorhhgpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphho shhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 7 Mar 2025 13:54:00 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1741373637; bh=jFTtGll5wxvhMzpjzWwuAOA6dlLhhEMBh5uMWk1NRGk=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=n1b2BifFRfEFEzmwSdUyGrsT6ifMtmZWYHi3pB8FBE8b8Mrxy6QDYjxu5qLzunidH 7A3H+MnF3DvvGV3QPCfWZ/kymmh3ynaT3ng1bLp+xsJARh4Bt2gnTb0XW49uyS2Irn RFv4kA4E1B+OKCEA84tmsMcX2CgMpqfIJQolz49fsEgww7l4BId2Q/BXzvhVpu9jEa fY88iXXGFj4Ap8K81/8zzEWz5yPwtg9E3tzD/OUB/FZQsiagJ1hwqdMIOAthAg3gol XCNsR68OoXcP6cXEOlvi29d0F+Wc5E91w9yh3kEwU1GS21mzzuL/5W7l1GT6Wnu1+a NLAYXVytqQagQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 629A58F; Fri, 7 Mar 2025 19:53:57 +0100 (CET) Date: Fri, 7 Mar 2025 19:53:57 +0100 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Ranier Vilela Cc: Pg Hackers , Alexander Korotkov , Maxim Orlov , Svetlana Derevyanko Subject: Re: Simplify the logic a bit (src/bin/scripts/reindexdb.c) Message-ID: <202503071853.5fd6bjxakhe2@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 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 Hello I find that this is still quite broken -- both the original, and your patch. I have already complained about a fundamental bug in the original in [1]. In addition to what I reported there, in the unpatched code I noticed that we're wasting memory and CPU by comparing the qualified table name, when it would be faster to just store the table OID and do the comparison based on that. Because the REINDEX INDEX query only needs to specify the *index* name, not the table name, we don't need the table name to be stored in the indices_tables_list: we can convert it into an OID list and store that instead. The strcmp becomes a numeric comparison. Yay. This is of course a pretty trivial, almost meaningless change. [1] https://postgr.es/m/202503071820.j25zn3lo4hvn@alvherre.pgsql But your patch also makes the mistake that indices_table_list is passed as a pointer by value, so the list that is filled by get_parallel_tabidx_list() can never have any effect. I wonder if you tested this patch at all. With your patch and the sample setup I posted in [1], the program doesn't do anything. It never calls REINDEX at all. It is a dead program. It's so bogus that in fact, there's no program, it's just a bug that takes a lot of disk space. For this to work, we need to pass that list (the output list) as a pointer reference, so that the caller can _receive_ the output list. We also get this compiler warning: /pgsql/source/master/src/bin/scripts/reindexdb.c: In function ‘get_parallel_tabidx_list’: /pgsql/source/master/src/bin/scripts/reindexdb.c:782:17: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] 782 | if (cell != index_list->head) | ^~ /pgsql/source/master/src/bin/scripts/reindexdb.c:785:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ 785 | appendQualifiedRelation(&catalog_query, cell->val, conn, echo); | ^~~~~~~~~~~~~~~~~~~~~~~ Not to mention the 'git apply' warnings: I schmee: master 0$ git apply /tmp/v3-simplifies-reindex-one-database-reindexdb.patch /tmp/v3-simplifies-reindex-one-database-reindexdb.patch:191: space before tab in indent. fmtQualifiedIdEnc(PQgetvalue(res, i, 1), /tmp/v3-simplifies-reindex-one-database-reindexdb.patch:192: space before tab in indent. PQgetvalue(res, i, 0), /tmp/v3-simplifies-reindex-one-database-reindexdb.patch:193: space before tab in indent. PQclientEncoding(conn))); advertencia: 3 líneas agregan errores de espacios en blanco. Anyway, my version of this is attached. It fixes the problems with your patch, but not Orlov's fundamental bug. Without fixing that bug, this program does not deserve this supposedly parallel mode that doesn't actually deliver. I wonder if we shouldn't just revert 47f99a407de2 completely. You, on the other hand, really need to be much more careful with the patches you submit. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "Selbst das größte Genie würde nicht weit kommen, wenn es alles seinem eigenen Innern verdanken wollte." (Johann Wolfgang von Goethe) Ni aún el genio más grande llegaría muy lejos si quisiera sacarlo todo de su propio interior.