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 1u0T6h-001bsJ-6T for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Apr 2025 22:32:19 +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 1u0T6f-00BRmr-Lq for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Apr 2025 22:32:17 +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 1u0T6f-00BRmi-CG for pgsql-hackers@lists.postgresql.org; Thu, 03 Apr 2025 22:32:17 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u0T6d-003FBy-0t for pgsql-hackers@lists.postgresql.org; Thu, 03 Apr 2025 22:32:17 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 533MWCd21594741; Thu, 3 Apr 2025 18:32:12 -0400 From: Tom Lane To: m.litsarev@postgrespro.ru cc: Ivan Kush , samimseih@gmail.com, pgsql-hackers@lists.postgresql.org Subject: Re: pg_stat_statements: improve loading and saving routines for the dump file In-reply-to: <0231a188cf457095458ba9759ac21ea1@postgrespro.ru> References: <192f7185defa370d083e3a237727b066@postgrespro.ru> <63fd7f0d-2d49-4952-b1ec-fa877bbf0765@tantorlabs.com> <181d7759a2ed7d819add4e0086e7a7f9@postgrespro.ru> <0231a188cf457095458ba9759ac21ea1@postgrespro.ru> Comments: In-reply-to m.litsarev@postgrespro.ru message dated "Wed, 22 Jan 2025 16:54:40 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1594739.1743719532.1@sss.pgh.pa.us> Date: Thu, 03 Apr 2025 18:32:12 -0400 Message-ID: <1594740.1743719532@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk m.litsarev@postgrespro.ru writes: >> What does this patch give on aglobal scale? Does it save much memory or >> increase performance? How many times? > This patch makes the code semantically more correct and we don't lose > anything. It is obviously not about performance or memory optimisation. Indeed not: on my machine I see sizeof(pgssEntry) = 432. It's full of int64 fields, so the alignment requirement is 8 bytes, meaning that the mutex field accounts for 8 bytes even though it's likely just 1 or 4 bytes wide. Still, that means what you suggest is only going to save 8/432 = 1.8% of the on-disk size of the struct. Given that we also store the SQL query text for each entry, the net savings fraction is even smaller. I don't really agree that this is adding any semantic correctness either. If we were reading directly into a live hashtable entry, overwriting the mutex field could indeed be bad. But the fread() call is reading into a local variable "temp" and we only copy selected fields out of that. So it's just some bytes in a transient stack entry. On the whole therefore, I'm inclined to reject this on several grounds: * The savings is not worth the costs of bumping the stats file format magic number (and thereby invalidating everyone's stored statistics). * I'd rather keep the flexibility to put the mutex wherever we want in the struct. Right now that isn't worth much either, but depending on what fields get added in future, we might have the opportunity to move the mutex to someplace where it fits into padding space and hence adds nothing to sizeof(pgssEntry). * Adding the requirement on where the mutex is makes the code more fragile, since somebody might ignore the comment and place things incorrectly. I'd like to think that such an error would be spotted immediately, but we've committed sillier mistakes. The consequences would likely be that some fields don't get stored/reloaded correctly, which might escape notice for awhile. regards, tom lane