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 1vj06b-003SAB-2E for pgsql-general@arkaria.postgresql.org; Thu, 22 Jan 2026 19:12:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vj06a-00EEJa-1r for pgsql-general@arkaria.postgresql.org; Thu, 22 Jan 2026 19:12:32 +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.96) (envelope-from ) id 1vj06a-00EEJS-0m for pgsql-general@lists.postgresql.org; Thu, 22 Jan 2026 19:12:32 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vj06W-001ohi-1r for pgsql-general@lists.postgresql.org; Thu, 22 Jan 2026 19:12:31 +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 60MJCRNn2770957; Thu, 22 Jan 2026 14:12:28 -0500 From: Tom Lane To: Nicolas Seinlet cc: "pgsql-general@lists.postgresql.org" Subject: Re: pg_trgm upgrade to 1.6 led to load average increase In-reply-to: References: <2215067.1769012876@sss.pgh.pa.us> Comments: In-reply-to Nicolas Seinlet message dated "Thu, 22 Jan 2026 12:10:33 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2770955.1769109147.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 22 Jan 2026 14:12:27 -0500 Message-ID: <2770956.1769109147@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nicolas Seinlet writes: > With pg_trgm=3D1.5: > QUERY PLAN > ----------- > Index Scan using ir_model_data_module_name_uniq_index on ir_model_data = (cost=3D0.56..2.58 rows=3D1 width=3D17) (actual time=3D0.027..0.028 rows=3D= 1 loops=3D1) > Index Cond: (((module)::text =3D 'base'::text) AND ((name)::text =3D = 'public_user'::text)) > Planning Time: 0.093 ms > Execution Time: 0.050 ms > (4 rows) > With pg_trgm=3D1.6: > QUERY PLAN > ---------- > Index Scan using ir_model_data_name_idx2 on ir_model_data (cost=3D0.42= ..2.44 rows=3D1 width=3D17) (actual time=3D8403.936..9847.983 rows=3D1 loo= ps=3D1) > Index Cond: ((name)::text =3D 'public_user'::text) > Rows Removed by Index Recheck: 10 > Filter: ((module)::text =3D 'base'::text) > Planning Time: 1.564 ms > Execution Time: 9848.027 ms > (6 rows) Hmm, so the cost estimates are nearly the same for both index types. I can reproduce that locally if the gist-indexed column is estimated to have only one match; then the additional index condition isn't believed to improve the selectivity any, so the planner has no motivation to prefer using the two-column index. What I don't reproduce here is the huge differential in actual cost. The gist index is a bit slower for me, but not five orders of magnitude slower. However, my test table isn't huge --- about 80K rows --- and I suppose from these numbers that yours must be far larger. So I'm thinking that the default signature length for gist_trgm_ops isn't large enough for your data set and what you want to do is make it bigger: CREATE INDEX ... USING GIST (name gist_trgm_ops(siglen =3D X)); The default value is 12 bytes, so maybe try 24 or 32. That will result in an index that's physically larger, but with luck less of it will need to be scanned for any one query. regards, tom lane