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 1nCgeD-0003Ee-LV for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 11:39:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nCgeC-0005Q3-Ge for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 11:39:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCgeC-0005Pu-6G for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 11:39:32 +0000 Received: from ms-10.1blu.de ([178.254.4.101]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCge8-000147-Uo for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 11:39:31 +0000 Received: from [188.174.53.237] (helo=pureos) by ms-10.1blu.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nCge7-0003cF-OP; Wed, 26 Jan 2022 12:39:27 +0100 Date: Wed, 26 Jan 2022 12:39:25 +0100 From: Matthias Apitz To: Josef =?utf-8?B?xaBpbcOhbmVr?= Cc: pgsql-general Subject: Re: SELECT with LIKE clause makes full table scan Message-ID: Reply-To: Matthias Apitz References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 El día miércoles, enero 26, 2022 a las 12:20:08 +0100, Josef Šimánek escribió: > st 26. 1. 2022 v 11:55 odesílatel Matthias Apitz napsal: > > > > > > 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: > > Which index is ignored? Can you share the CREATE INDEX command as well? /* # $Revision: 1.1.2.21 $ */ create UNIQUE INDEX d01sig on d01buch(d01gsi,d01ex) ; /* alter table d01buch add constraint d01sig unique (d01gsi,d01ex) deferrable initially deferred; *//* D01SIG */ create INDEX d01mcopyno on d01buch(d01mcopyno) ;/* D01MCOPYNO */ create INDEX d01bnr on d01buch(d01bnr) ;/* D01BNR */ create INDEX d01ort on d01buch(d01ort) ;/* D01ORT */ create INDEX d01mcopynozweig on d01buch(d01mcopyno,d01zweig) ;/* D01KATZWEIG */ create INDEX d01ort2 on d01buch(d01ort2) ;/* D02ORT2 */ create INDEX d01aufnahme on d01buch(d01aufnahme) ;/* D01aufnahme */ create INDEX d01titlecatkey on d01buch(d01titlecatkey) ;/* D01TITLECATKEY */ create INDEX d01invkrnr on d01buch(d01invkreis,d01invnr) ;/* D01invkrnr */ matthias > > 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 > > > > -- Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045 Public GnuPG key: http://www.unixarea.de/key.pub