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 1rAE8O-005WaL-6A for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Dec 2023 18:57:36 +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 1rAE8M-000pm1-T5 for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Dec 2023 18:57:34 +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 1rAE8M-000plp-FF for pgsql-hackers@lists.postgresql.org; Mon, 04 Dec 2023 18:57:34 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rAE8J-00A5yd-Gz for pgsql-hackers@postgresql.org; Mon, 04 Dec 2023 18:57:33 +0000 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1d0a7b72203so10700485ad.2 for ; Mon, 04 Dec 2023 10:57:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1701716248; x=1702321048; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=jpKnPsEwicthicc5j6hGKppnzcXaeixTT/q2gsNP6QI=; b=BoMFa9GVxHtsvOHybovlbPEbfHYOzprPr1dC14OyNnJMCF3kIlJCiXxtcBeWlqdd17 aAISteA13bw5cuDuIa5skxtzi3R6CtRgZCDdFEugMNHG0dy4v3+3BZwUQ/lVPE2uEPm1 sSWQLZGXnbDWlVMYVqkUmwSZwWcqRRMnPMWmXcrMuDjK3pza+JKq9HJyuBxLKBbVmA22 G36x+4qnWlPbrj2OQLdhpdRxZ354djP0+WdpUxRO+PYCIGLDHecxSIM3etyZzaWzz4gY C8JQgjCGHPLpV/x8RzSPMEWXG8RCwfaXnaDgNjHl6pjduezs9wHNKiWuo5iNIg74S7cB ReaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701716248; x=1702321048; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=jpKnPsEwicthicc5j6hGKppnzcXaeixTT/q2gsNP6QI=; b=fYRI8UOcjuZ14ly+JSsMHSn9Tn3evpMkROyQXlsCqL3DduY7mdV2v0MiyfS7nNlaLC JUVXfaFFX8L/LK0rqLWRpyA58TOPQTnTUdbjHY3TiKjppoEbzI+txi/Vzx6iyqN/8q+p jwV+86rbgp5aj41KaX0JDAbpDCy7gfUPdIo6iTBd5X9KRDIwNQvHXpj6OWdW3X+QoB1T WtuPqkqhlKbDlTElff4ndhtR6i0W4XbAPCf/MKHheHa1w4aAw+AXuF8wKxTF8ipSEriO UH3+SkloPnL6852nSWe77WS85F3FVlFDCOKpzfZEY569U5WuzvhN80H7hHZV3D51MZIV jINw== X-Gm-Message-State: AOJu0Yy/bj+vxOOnZNlL+qJySZaY2cF5aiTOu1Om67ecPcqBORxltGGn GzqPyU9Fr/zX3zmgzHoTYUlHpA== X-Google-Smtp-Source: AGHT+IED8Zq2sLh4vzPjps0IOAFJwdXErZ+pIZ9H0+EFSi3sPrkw/0VH9J0Z0lQKVsvL0cm1yumv+A== X-Received: by 2002:a17:902:f7c4:b0:1cf:c901:5451 with SMTP id h4-20020a170902f7c400b001cfc9015451mr4109253plw.14.1701716248453; Mon, 04 Dec 2023 10:57:28 -0800 (PST) Received: from [172.18.10.36] ([12.126.244.130]) by smtp.gmail.com with ESMTPSA id l7-20020a170902f68700b001cc2ebd2c2csm6045786plg.256.2023.12.04.10.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 10:57:28 -0800 (PST) Message-ID: Subject: Re: Change GUC hashtable to use simplehash? From: Jeff Davis To: John Naylor Cc: Andres Freund , Tom Lane , Gurjeet Singh , pgsql-hackers@postgresql.org Date: Mon, 04 Dec 2023 10:57:27 -0800 In-Reply-To: References: <20231117232712.mpnzsho7ydssg2oc@awork3.anarazel.de> <7fee9f31c2e82948fa56fe57d68eecb0cce36f10.camel@j-davis.com> <20231118001003.n2d7tvdgeckun2y6@awork3.anarazel.de> <27a7a289d5b8f42e1b1e79b1bcaeef3a40583bd2.camel@j-davis.com> <20231122205030.v6yllmmj6dgxpg5f@awork3.anarazel.de> <2330615.1700686581@sss.pgh.pa.us> <20231122212221.ahmlio2yfx7jla6z@awork3.anarazel.de> <2334462.1700688476@sss.pgh.pa.us> <20231122223432.lywt4yz2bn7tlp27@awork3.anarazel.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2023-12-04 at 12:12 +0700, John Naylor wrote: > That's a good thing to clear up. This thread has taken simplehash as > a > starting point from the very beginning. It initially showed no > improvement, and then we identified problems with the hashing and > equality computations. The latter seem like independently commitable > improvements, so I'm curious if they help on their own, even if we > still need to switch to simplehash as a last step to meet your > performance goals. There's already a patch to use simplehash, and the API is a bit cleaner, and there's a minor performance improvement. It seems fairly non-controversial -- should I just proceed with that patch? > > If I understood what Andres was saying, the exposed hash state > > would be > > useful for writing a hash function like guc_name_hash(). >=20 > From my point of view, it would at least be useful for C-strings, > where we don't have the length available up front. That's good news. By the way, is there any reason that we would need hash_bytes(s, strlen(s)) =3D=3D cstring_hash(s)? > > Also, while the |=3D 0x20 is a nice trick for lowercasing, did we > > decide > > that it's better than my approach in patch 0004 here: > >=20 > > https://www.postgresql.org/message-id/27a7a289d5b8f42e1b1e79b1bcaeef3a4= 0583bd2.camel@j-davis.com > >=20 > > which optimizes exact hits (most GUC names are already folded) > > before > > trying case folding? >=20 > Note there were two aspects there: hashing and equality. I > demonstrated in >=20 > https://www.postgresql.org/message-id/CANWCAZbQ30O9j-bEZ_1zVCyKPpSjwbE4u1= 9cSDDBJ%3DTYrHvPig%40mail.gmail.com >=20 > ... in v4-0003 that the equality function can be optimized for > already-folded names (and in fact measured almost equally) using way, > way, way less code. Thinking in terms of API layers, there are two approaches: (a) make the hash and equality functions aware of the case-insensitivity, as we currently do; or (b) make it the caller's responsibility to do case folding, and the hash and equality functions are based on exact equality. Each approach has its own optimization techniques. In (a), we can use the |=3D 0x20 trick, and for equality do a memcmp() check first. In (b), the caller can first try lookup of the key in whatever form is provided, and only if that fails, case-fold it and try again. As a tangential point, we may eventually want to provide a more internationalized definition of "case insensitive" for GUC names. That would be slightly easier with (b) than with (a), but we can cross that bridge if and when we come to it. It seems you are moving toward (a) whereas my patches moved toward (b). I am fine with either approach but I wanted to clarify which approach we are using. In the abstract, I kind of like approach (b) because we don't need to be as special/clever with the hash functions. We would still want the faster hash for C-strings, but that's general and helps all callers. But you're right that it's more code, and that's not great. Regards, Jeff Davis