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.96) (envelope-from ) id 1vJBq0-00DvQI-2a for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Nov 2025 14:28:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vJBpy-00C3V2-1g for pgsql-hackers@arkaria.postgresql.org; Wed, 12 Nov 2025 14:28:42 +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.96) (envelope-from ) id 1vJBpy-00C3Uu-0m for pgsql-hackers@lists.postgresql.org; Wed, 12 Nov 2025 14:28:42 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vJBpw-007MGM-0y for pgsql-hackers@lists.postgresql.org; Wed, 12 Nov 2025 14:28:41 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-47789cd2083so4152055e9.2 for ; Wed, 12 Nov 2025 06:28:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762957719; x=1763562519; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=AwOgkf1a/lohrQIu8qLzzdIIfZD+2sIosGzE7QYSVS4=; b=XBRFXgrp4zchcGLPk+ap44DVyUw2hObcxp6nojYhrLU8kekDwlFs8VXl9nybhF2bRk aQsNNPEK2V9qFvg2Ekut9+L3xF8FNM7K2CVOFHUHPBWwMprFjPlgh4lDNwsO8CVAT5Yq NnNg7++rcTqGDmERHcoPxeOWYTudxViLweeTE+vV/jCRVZy1agGpNdqxgUG5AF9voHdX mdBAAj/zqNj/QUkIXIfz/4M/mlo65idiejPyFywrMT8YZxBxfFWg3O8LfHX6NM6hkEQm P+O490eJIF1Ty+CN5WOTVqjfOWHPMxT63+eZ3JdKkRWUl20258C0d3iTU2I/kk+SkiWx y8Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762957719; x=1763562519; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AwOgkf1a/lohrQIu8qLzzdIIfZD+2sIosGzE7QYSVS4=; b=F2DqET1V3YBF/lGaFaBavzCz/dlMvuhCUv+HqASkmoKMWwdwMrTP/VNWbd8kRXiAIW y3u9hLPLFrvV5v+npu9otOMKBCYZrSiUod0Jopb4TbeZD+EXfgzXpAsWR1gv0lSA7dy5 9Pt3sLnKZiazI2PVc41z17pLzgvFrljsYbg6AtpnMZ06xrlNJGuPno6brVpTqR4Kalkh KBTOLl+AbD3Z0miRgqhK8es0/Sr6L2ExOB/PzbbQydNaCU0amBmHak87cp4wvMSmR5ko yV93TvhYqZrUxmLTGeSdm8GmeqzrYmQfAFp+6eN0/EcjaEE7m0jEIVU0FVLhs9xN/KDu Aoew== X-Forwarded-Encrypted: i=1; AJvYcCWTX3PeSm+T5XiNpajC/nBwG+J7ocAwgAxbCo7w9k9MIEoo8XD3vvREV3rW0hhRF10NVl9rcrvNcSLpH3fF@lists.postgresql.org X-Gm-Message-State: AOJu0YxJm1xLqFaWohL8/u/TYjlILlvUp56JHfdMKyoPxmFCtFn5J4Zl VWPEmCdLO5rbgqlFpuZeOKzzlMdanAcVNvMGrMF8Vx9A3zm4UPq8QWdR X-Gm-Gg: ASbGncugqUtAN4u+b1BMHFuJlOki54gLHPBLG9CrAooaSI2AE2i5H4e6K4/WcIX3wm3 Ov5P0zDYyhNlHwrDN4+ghGBoPPq39LcHO6S1uf9jAPaevXLqz098gXAJkNhWQIg9sRGG92HEzMJ ZRoAJzxc+ssVKi7Pb4tZkplkWQayKMZHZ4UmaOjSeABBfqA6Gh8WBChYvmovzoPNUlRv/WI+AL9 aGBa8tSuPnBUuB7cvcyiyGmLYMP3UsBhKQ8EDEdSkyxkmHN3PS3RNbFOzPxX54fLvG3jNIXaIrf 6+zPXZ+8QoDvtx9wvKnH8wD19VYfgksuapk2YG+duPgkkmQZs+7G1oAHaYHsWT8GSgLpZIURj6D dppB207QdxC2v7V3fBDvYG2t01+fGrezVAV7jANovIEgBA9QFK2LeGxi/8TFGd15ece7rXe2SLG 9vSfynaHTUGko3 X-Google-Smtp-Source: AGHT+IGiPo5jVKaHHROMEU4F9n+45V5vBT1I3fuEjl+7TUboM49dnn85X5TCzkHnzgtGSYznRucuOg== X-Received: by 2002:a05:600c:26d1:b0:477:8985:4039 with SMTP id 5b1f17b1804b1-4778a01e47amr9028915e9.17.1762957718729; Wed, 12 Nov 2025 06:28:38 -0800 (PST) Received: from [192.168.2.32] ([165.225.27.26]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-42ac67921c3sm35011431f8f.40.2025.11.12.06.28.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Nov 2025 06:28:38 -0800 (PST) Message-ID: Date: Wed, 12 Nov 2025 15:28:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: tuple radix sort To: John Naylor , PostgreSQL Hackers Cc: Peter Geoghegan References: Content-Language: en-US From: David Geier In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 29.10.2025 07:28, John Naylor wrote: > > Next steps: Try to find regressions (help welcome here). The v1 patch > has some optimizations, but in other ways things are simple and/or > wasteful. Exactly how things fit together will be informed by what, if > anything, has to be done to avoid regressions. I suspect the challenge > will be multikey sorts when the first key has low cardinality. This is > because tiebreaks are necessarily postponed rather than taken care of > up front. I'm optimistic, since low cardinality cases can be even > faster than our B&M qsort, so we have some headroom: Hi John, I've also been looking into radix sort the last days to accelerate GIN index builds. Ordering and removing duplicates requires a fast sort in generate_trgm(). My own implementation (likely slower than the algorithms you used) also showed a decent speedup. Beyond that there are many more places in the code base that could be changed to use radix sort instead of qsort. What would be great is if we could build a generic radix sort implementation, similarly to sort_template.h that can be used in other places. We would have to think a bit about the interface because instead of a comparator we would require some radix extraction callback. If you're open to that idea I could give abstracting the code a try. -- David Geier