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 1to9Bc-006p69-Re for pgsql-performance@arkaria.postgresql.org; Fri, 28 Feb 2025 22:50:29 +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 1to9Bc-000Vzo-No for pgsql-performance@arkaria.postgresql.org; Fri, 28 Feb 2025 22:50:27 +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 1to9Bc-000VzY-Dq for pgsql-performance@lists.postgresql.org; Fri, 28 Feb 2025 22:50:27 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1to9BZ-000FbR-0U for pgsql-performance@lists.postgresql.org; Fri, 28 Feb 2025 22:50:26 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-2bcdce44e56so286278fac.0 for ; Fri, 28 Feb 2025 14:50:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740783024; x=1741387824; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BZjVjpUieihL7zVNaKVwesE8yN1QKVCpkDvcN1BqSwo=; b=TPdctuerftbY2clILhRJPVyPNc7olkyDl5nVtF0qpB+wAF+WCQ2X1aKmohwJDV+Ij5 AOqkui9/Yh78cJEFD83QtCF7mUlthlyPf5t4RG0saHK1Qm2i5LWYlQZSMYPmRA5n7aYW hjQHegwdnCWjsDKnLtfxR/BMyU5+AzF2cE6EgahJc9Kp3PvSsq97e9IMpqCrxhVUh5Xw O3qGfo5qYoMdZbxRzJSVu3NIZVj9viKfImCJBp2ziB47DmvaH3nerTS0RzvECh7TLAQa 1EB6mmZiQKS2778djQx6F0DdcT86IiTlC9nfkkJkFQN/dQ9cxwkYmbB1ykjaNwROKiCF Pmuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740783024; x=1741387824; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BZjVjpUieihL7zVNaKVwesE8yN1QKVCpkDvcN1BqSwo=; b=V69ho2lL4AtR9q4MIpAy+WhIvDwY8GRF50+ocso8Sra73VR6LQcq8GH4d3T0K0yQTQ aOfIuXykyZ6QxeqE2l9WAn46RCitBSZUrnWp+j7LnnDJbIYrDHRY8QueGnra2SJ/iP0T AfBEA2UWpxDNIKGvHJQj8LgmKxwfYlZ5eYlSUORwfe/n9y3yGIGAg/oW5rQLby4DadwF eaYIPZBS69T1m72CcsDSSuGmbdPXrgXwjvij85v4ebfc/wsQFRPFZ+ZQhILN/eC2vXS8 Lbfn24EC8Zi56yC8iWCDWS5poVACkDY85Wj3TbCm+wYPtnuIgQ2VCaWLVmiVtQj8gx4v xtDw== X-Forwarded-Encrypted: i=1; AJvYcCVlDesTEZb/nMOnG7rkhgQy7iR+STAfKT3FxWAOZmRzgdFVyAtu5iEa2DIGrfOGmnXKlQ2iPqjb345uquJ0NYQ5cA==@lists.postgresql.org X-Gm-Message-State: AOJu0Yy+I7qst4gQSKLql/tniNW36WLSkD9ZLlcxxGE8VnKeke3DL5Np XTIQq0gY8MzeScvVowHnrT8ILGd3r3MxWmMRQ2E31YgxV0oo0BD90FDtDkDcJrbWTQyYUp6gl+I DZuy2DmgjhVsZlp1/WowyCJuVpJRVLyXpIyQ= X-Gm-Gg: ASbGncsVEp+nWObTAjM4VjA4zUHoja2fMd42HU6Jab4dakhx1c33+1FM7Kai9MheTTi VhJYT2YhNk2C55Lt7/R4FORWZ32LcT9zotZj9fAD3jAPb8TTNUkNGsrfvEG5zBhBmjDLiOLVHKX aSU3ZZePYG2/H2ucNLuYnvFgXEBsE= X-Google-Smtp-Source: AGHT+IFMfQswu+hWpXYdPTyVK81Mm1QscXTE1G3vVqGD/LqJwy3JxVmA6f2UbF/GEpiUUUe2XgKoyehFDA3zcTLud+A= X-Received: by 2002:a05:6808:1a01:b0:3f4:7a9:7bc4 with SMTP id 5614622812f47-3f558619370mr1309787b6e.9.1740783024457; Fri, 28 Feb 2025 14:50:24 -0800 (PST) MIME-Version: 1.0 References: <1ab051d93e215a31b2a7af9b522c918bca9b484f.camel@cybertec.at> In-Reply-To: From: Thomas Munro Date: Sat, 1 Mar 2025 11:49:38 +1300 X-Gm-Features: AQ5f1JqrfUCE2OZyl7spsXtjJuH7QA_u2Snx7bLa4D_lc-jvgTDpLsTwSij0Jq4 Message-ID: Subject: Re: Slow performance of collate "en_US.utf8" To: Joe Conway Cc: Laurenz Albe , Alexey Borschev , pgsql-performance@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Mar 1, 2025 at 9:03=E2=80=AFAM Joe Conway wrot= e: > On 2/28/25 09:16, Laurenz Albe wrote: > > On Thu, 2025-02-27 at 16:54 +0300, Alexey Borschev wrote: > >> I see poor performance of text sorting of collate "en_US.utf8" in PG 1= 7.4. > > > > I'd say that you would have to complain to the authors of the > > GNU C library, which provides this collation. > > Yep -- glibc starting with version 2.21 has a massive performance > regression for certain cases and the glibc folks have basically said > they will not fix it. If you try the same thing on RHEL 7.x with glibc > 2.17 it will perform about the same as ICU. I've idly wondered if this is the culprit, do you know? https://github.com/bminor/glibc/commit/0742aef6e52a935f9ccd69594831b56d807f= eef3 It seems to have bet that strings either differ in primary weight as early as they do in synthetic natural language tests, or not at all because they are equal and that is detected with a fast-path binary comparison. The average first different character word-to-word in my /usr/shared/dict/words is at position ~5.6 (some kind of worst case as it is already sorted), cf 14+ multibyte sequences in OP's example, which must be well outside their test parameters I would guess. I didn't read the code but the description has a miasma of quadratic-catching-on-fire about it: it's now rescanning the secondary weights with repeated traversals, because the cache they ripped out wasn't pulling its own weight at small common prefix sizes, or something like that? I wonder if 2.21 also got faster for PostgreSQL sorting /usr/share/dict/words as you might expect from that description. Database keys with long common prefixes *probably* shouldn't be using natural language sorting anyway, so "don't do that", but knowledge of collations is not well distributed... on the other hand I suspect you can dream up some real natural language examples that lose the bet too: sort "lastname, firstname" across a country of 300 million, maybe?