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 1ohT2p-0005BY-MM for pgsql-general@arkaria.postgresql.org; Sun, 09 Oct 2022 09:56:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ohT2n-0002EU-DU for pgsql-general@arkaria.postgresql.org; Sun, 09 Oct 2022 09:56:25 +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 1ohT2m-0002EL-Sm for pgsql-general@lists.postgresql.org; Sun, 09 Oct 2022 09:56:25 +0000 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ohT2g-0000me-3L for pgsql-general@lists.postgresql.org; Sun, 09 Oct 2022 09:56:23 +0000 Received: by mail-oo1-xc32.google.com with SMTP id s125-20020a4a5183000000b0047fbaf2fcbcso4162752ooa.11 for ; Sun, 09 Oct 2022 02:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to; bh=Fpi3KNLKSb/DeJKpJFuyotfMvramPf9n+wfmDn9GjtI=; b=qWApgSL7888z0YOZxHlNcqm6Ya7gu3sOpWodKrFgRVBrJEs4X04ACotvmHrrwdNn56 m36DQoxQs2qaVi1i9l7r8R5Jd3V+TuvZMTSzYrKUbI+BCubW7jGA7zehMDJcQTe8OFHV UaP+oOAfAi7stdpghnHPgXcRx4rybjgJ9G+Dgo2Ji8jk0ThsiEmCnxQ38V+TZRFSN2kU B+3B7Ie6z+wghkjNUiRy2Uf0bW1W04XALN8MwdcbTIwEws8RxqqvEUnrnVpdXySkb85Q a6cXu5YAwMdmH4woNhabgUO8V884oY/sRQf0aRj7RktL+20a29C/hRN6dDKYHwWGcCi1 /Kvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=Fpi3KNLKSb/DeJKpJFuyotfMvramPf9n+wfmDn9GjtI=; b=b156Mk21tdKivOyxkRbbFfYCcTrCN3XyNKaME06WAnz2UN4LpFjW4SGWipGJ/w9jsr /c4iB0mC9HkLAxQ2YongjFNoIwKmgpfp+jdQa6tjnQviU7FBXV7kS0oCrMVqhEYr2Hor 2ENVvmrICSFcnTViG+QuYq/ei/fpdeSyWrNzGh7HvZ0O08cLEaOtaaJsxadmAwcLq0oM DbZ8dR2VTyfxFSrkMRcl/ehB6JEK4BDmlbuG5Wt/Kuqtbqjiyc41quAvBQEih0nodqtG 5QMovFA3mO0VKXAKL0eQ601fhAtldH5aJT1cSH/5eFoPxs6xLAkSjiUlv2gxCZ4yIXiZ BpIw== X-Gm-Message-State: ACrzQf2YMZf7isVvS0xD9QJNRbK4LELj/kCtOph0o1nDO1g4v52E22CX jZDNmmkEaYWkZqXXxCpg7HbeHeqfKFc= X-Google-Smtp-Source: AMsMyM6WdjWkIANsp3OPkx5XlM1N2WPyaooa5TtiE7XJJp3QUrEpv6jH6zULY93vhG9bpKeZ3gPhpA== X-Received: by 2002:a05:6830:6315:b0:661:8cab:7ab0 with SMTP id cg21-20020a056830631500b006618cab7ab0mr2739281otb.264.1665309377050; Sun, 09 Oct 2022 02:56:17 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id d9-20020a0568301b6900b0063b2875246dsm3707110ote.49.2022.10.09.02.56.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 Oct 2022 02:56:16 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------TZaRFSFg2NUASZSsieu0sx4w" Message-ID: Date: Sun, 9 Oct 2022 04:56:15 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: Different execution plan between PostgreSQL 8.4 and 12.11 Content-Language: en-US To: pgsql-general@lists.postgresql.org References: <23fe7e4b.5866.183bc03584f.Coremail.gzhcoder@126.com> From: Ron In-Reply-To: <23fe7e4b.5866.183bc03584f.Coremail.gzhcoder@126.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------TZaRFSFg2NUASZSsieu0sx4w Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Did you analyze and vacuum all of the tables in the new database? On 10/9/22 04:11, gzh wrote: > > Hi, > > > I have had a Perl Website working for 7 years and have had no problems > > until a few weeks ago I replaced my database server with a newer one. > > > Database server (old): PostgreSQL 8.4 32bit > > Database server (new): PostgreSQL 12.11 64bit > > > I run following sql in PostgreSQL 8.4 and PostgreSQL 12.11, it returns > different execution plan. > > > --PostgreSQL 8.4 > > --------------- > > > old=# select count(1) from analyze_word_reports; > >   count > > --------- > >  9164136 > > (1 row) > > > old=# select indexdef from pg_indexes where tablename='analyze_word_reports'; > >  indexdef > > ------------------------------------------------------------------------------------------- > >  CREATE INDEX analyze_word_reports_index_cseid ON analyze_word_reports > USING btree (cseid) > >  CREATE UNIQUE INDEX analyze_word_reports_pkey ON analyze_word_reports > USING btree (seq) > > (2 rows) > > > old=# explain analyze select 2 from analyze_word_reports where (cseid = > 94) limit 1; > >                                  QUERY PLAN > > --------------------------------------------------------------------------------------------------------------------------------------------------------------------- > >  Limit  (cost=0.00..0.63 rows=1 width=0) (actual time=0.893..0.893 rows=0 > loops=1) > >    ->  Index Scan using analyze_word_reports_index_cseid on > analyze_word_reports (cost=0.00..18621.98 rows=29707 width=0) (actual > time=0.892..0.892 rows=0 loops=1) > >          Index Cond: (cseid = 94) > >  Total runtime: 0.941 ms > > (4 rows) > > > > --PostgreSQL 12.11 > > --------------- > > > new=# select count(1) from analyze_word_reports; > >   count > > --------- > >  20131947 > > (1 row) > > > new=# select indexdef from pg_indexes where tablename='analyze_word_reports'; > >  indexdef > > ------------------------------------------------------------------------------------------- > >  CREATE INDEX analyze_word_reports_index_cseid ON analyze_word_reports > USING btree (cseid) > >  CREATE UNIQUE INDEX analyze_word_reports_pkey ON analyze_word_reports > USING btree (seq) > > (2 rows) > > > new=# explain analyze select 2 from analyze_word_reports where (cseid = > 94) limit 1; > >                  QUERY PLAN > > ------------------------------------------------------------------------------------------------------------------------------------- > > Limit  (cost=0.00..0.41 rows=1 width=4) (actual time=4908.459..4908.462 > rows=1 loops=1) > >    ->  Seq Scan on analyze_word_reports (cost=0.00..528610.15 rows=1278561 > width=4) (actual time=4908.455..4908.456 rows=1 loops=1) > >          Filter: (cseid = 94) > >          Rows Removed by Filter: 15477750 > > Planning Time: 0.411 ms > > Execution Time: 4908.498 ms > > (6 行) > > > > Although PostgreSQL 8.4 has more than 10 million rows of data less than > PostgreSQL 12.11, > > PostgreSQL 12.11 is too slow and analyze_word_reports_index_cseid does not > seem to work. > > I'm guessing that the limit keyword of PostgreSQL 12.11 causes the index > not to work. > > But I don't understand why PostgreSQL 8.4 is normal. > > > What is the reason for this and is there any easy way to maintain > compatibility? > > > Regards, > > > -- > > > gzh > -- Angular momentum makes the world go 'round. --------------TZaRFSFg2NUASZSsieu0sx4w Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Did you analyze and vacuum all of the tables in the new database?

On 10/9/22 04:11, gzh wrote:

Hi, 


I have had a Perl Website working for 7 years and have had no problems

until a few weeks ago I replaced my database server with a newer one.


Database server (old): PostgreSQL 8.4 32bit

Database server (new): PostgreSQL 12.11 64bit


I run following sql in PostgreSQL 8.4 and PostgreSQL 12.11, it returns different execution plan.


--PostgreSQL 8.4

---------------


old=# select count(1) from analyze_word_reports;

  count

---------

 9164136

(1 row)


old=# select indexdef from pg_indexes where tablename='analyze_word_reports';

                                         indexdef

-------------------------------------------------------------------------------------------

 CREATE INDEX analyze_word_reports_index_cseid ON analyze_word_reports USING btree (cseid)

 CREATE UNIQUE INDEX analyze_word_reports_pkey ON analyze_word_reports USING btree (seq)

(2 rows)


old=# explain analyze select 2 from analyze_word_reports where (cseid = 94) limit 1;

                                                                             QUERY PLAN                                      

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

 Limit  (cost=0.00..0.63 rows=1 width=0) (actual time=0.893..0.893 rows=0 loops=1)

   ->  Index Scan using analyze_word_reports_index_cseid on analyze_word_reports  (cost=0.00..18621.98 rows=29707 width=0) (actual time=0.892..0.892 rows=0 loops=1)

         Index Cond: (cseid = 94)

 Total runtime: 0.941 ms

(4 rows)



--PostgreSQL 12.11

---------------


new=# select count(1) from analyze_word_reports;

  count

---------

 20131947

(1 row)


new=# select indexdef from pg_indexes where tablename='analyze_word_reports';

                                         indexdef

-------------------------------------------------------------------------------------------

 CREATE INDEX analyze_word_reports_index_cseid ON analyze_word_reports USING btree (cseid)

 CREATE UNIQUE INDEX analyze_word_reports_pkey ON analyze_word_reports USING btree (seq)

(2 rows)


new=# explain analyze select 2 from analyze_word_reports where (cseid = 94) limit 1;

                                                             QUERY PLAN                                                              

-------------------------------------------------------------------------------------------------------------------------------------

Limit  (cost=0.00..0.41 rows=1 width=4) (actual time=4908.459..4908.462 rows=1 loops=1)

   ->  Seq Scan on analyze_word_reports  (cost=0.00..528610.15 rows=1278561 width=4) (actual time=4908.455..4908.456 rows=1 loops=1)

         Filter: (cseid = 94)

         Rows Removed by Filter: 15477750

Planning Time: 0.411 ms

Execution Time: 4908.498 ms

(6 行)



Although PostgreSQL 8.4 has more than 10 million rows of data less than PostgreSQL 12.11,

PostgreSQL 12.11 is too slow and analyze_word_reports_index_cseid does not seem to work.

I'm guessing that the limit keyword of PostgreSQL 12.11 causes the index not to work. 

But I don't understand why PostgreSQL 8.4 is normal.


What is the reason for this and is there any easy way to maintain compatibility?


Regards,


--


gzh


--
Angular momentum makes the world go 'round.
--------------TZaRFSFg2NUASZSsieu0sx4w--