From: gzh <gzhcoder@126.com>
To: pgsql-general@lists.postgresql.org
Subject: Different execution plan between PostgreSQL 8.2 and 12.5
Date: Thu, 18 Aug 2022 11:01:04 +0800 (CST)
Message-ID: <6614e60.204d.182aee5aff0.Coremail.gzhcoder@126.com> (raw)
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.2 32bit
Database server (new): PostgreSQL 12.5 64bit
I run following sql in PostgreSQL 8.2 and PostgreSQL 12.5, it returns different execution plan.
--SQL
explain select
crew_base.crewid
from crew_base
left join crew_base as crew_base_introduced on crew_base.introduced_by=crew_base_introduced.crewid
where crew_base.status = '1';
--PostgreSQL 8.2
---------------
QUERY PLAN
Limit (cost=188628.24..189521.23 rows=10000 width=10)
-> Hash Left Join (cost=188628.24..3800200.71 rows=40443494 width=10)
Hash Cond: (lower(crew_base.introduced_by) = lower(crew_base_introduced.crewid))
-> Seq Scan on crew_base (cost=0.00..165072.69 rows=5446 width=20)
Filter: (status = 1)
-> Hash (cost=161359.55..161359.55 rows=1485255 width=10)
-> Seq Scan on crew_base crew_base_introduced (cost=0.00..161359.55 rows=1485255 width=10)
--PostgreSQL 12.5
---------------
QUERY PLAN
Limit (cost=0.43..47861.44 rows=10000 width=7)
-> Nested Loop Left Join (cost=0.43..169386135.30 rows=35391255 width=7)
Join Filter: (lower(crew_base.introduced_by) = lower(crew_base_introduced.crewid))
-> Seq Scan on crew_base (cost=0.00..128942.75 rows=4759 width=14)
Filter: (status = 1)
-> Materialize (cost=0.43..51909.70 rows=1487340 width=7)
-> Index Only Scan using crew_base_crewid_index on crew_base crew_base_introduced (cost=0.43..38663.00 rows=1487340 width=7)
PostgreSQL 8.2 quickly queried the data, but PostgreSQL 12.5 has not responded.
I'm guessing that the lower() function of PostgreSQL 12.5 invalidates the index.
But I don't understand why PostgreSQL 8.2 is normal.
What is the reason for this and is there any easy way to maintain compatibility?
Regards,
--
gzh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: gzhcoder@126.com
Subject: Re: Different execution plan between PostgreSQL 8.2 and 12.5
In-Reply-To: <6614e60.204d.182aee5aff0.Coremail.gzhcoder@126.com>
References: <6614e60.204d.182aee5aff0.Coremail.gzhcoder@126.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox