Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCfyM-0000wa-Uv for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 10:56:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nCfxp-0000u0-VS for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 10:55:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCfxp-0000tr-An for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 10:55:45 +0000 Received: from ms-10.1blu.de ([178.254.4.101]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCfxm-00039Q-LF for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 10:55:44 +0000 Received: from [188.174.53.237] (helo=localhost.unixarea.de) by ms-10.1blu.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCfxj-0002ml-IH; Wed, 26 Jan 2022 11:55:39 +0100 Received: from localhost.my.domain (localhost [127.0.0.1]) by localhost.unixarea.de (8.16.1/8.14.9) with ESMTPS id 20QAtcNx012909 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 26 Jan 2022 11:55:38 +0100 (CET) (envelope-from guru@unixarea.de) Received: (from guru@localhost) by localhost.my.domain (8.16.1/8.14.9/Submit) id 20QAtcI5012908; Wed, 26 Jan 2022 11:55:38 +0100 (CET) (envelope-from guru@unixarea.de) X-Authentication-Warning: localhost.my.domain: guru set sender to guru@unixarea.de using -f Date: Wed, 26 Jan 2022 11:55:38 +0100 From: Matthias Apitz To: pgsql-general@lists.postgresql.org Subject: SELECT with LIKE clause makes full table scan Message-ID: Reply-To: Matthias Apitz MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Operating-System: FreeBSD 13.0-CURRENT r368166 (amd64) X-message-flag: Mails containing HTML will not be read! Please send only plain text. X-Con-Id: 51246 X-Con-U: 0-guru X-Originating-IP: 188.174.53.237 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello, We face in a PostgreSQL 11.4 installation on a potent Linux host a serious performance degree. A SELECT with a LIKE clause on a table with ca. 5.200.000 rows on a column with an Index ignores this and does a full table scan: sisis=# explain (analyze, buffers) select * from d01buch where d01ort like 'Z 9610%' ; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------- Gather (cost=1000.00..680262.71 rows=510 width=952) (actual time=1324.096..1349.429 rows=1 loops=1) Workers Planned: 4 Workers Launched: 4 Buffers: shared hit=102040 read=560674 -> Parallel Seq Scan on d01buch (cost=0.00..679211.71 rows=128 width=952) (actual time=1117.663..1315.062 rows=0 loops=5) Filter: (d01ort ~~ 'Z 9610%'::text) Rows Removed by Filter: 1055853 Buffers: shared hit=102040 read=560674 Planning Time: 2.028 ms Execution Time: 1349.593 ms (10 Zeilen) Why is this (ignoring the Index) and what could be done? Thanks matthias -- Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045 Public GnuPG key: http://www.unixarea.de/key.pub