| From: | Kim Rose Carlsen <krc(at)hiper(dot)dk> | 
|---|---|
| To: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> | 
| Subject: | Remove useless joins (VARCHAR vs TEXT) | 
| Date: | 2017-09-16 20:07:07 | 
| Message-ID: | VI1PR05MB17091F9A9876528055D6A827C76D0@VI1PR05MB1709.eurprd05.prod.outlook.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general pgsql-hackers | 
Hi
It seems there are some difference in VARCHAR vs TEXT when postgres tries to decide if a LEFT JOIN is useful or not. I can't figure out if this is intentional because there are some difference between TEXT and VARCHAR that I dont know about or if it's a bug.
I would expect both examples to produce same query plan
a)
create table a (id varchar primary key);
create table b (id varchar primary key);
explain   select a.*
     from a
left join (select distinct id from b) as b
       on a.id = b.id;
                            QUERY PLAN
------------------------------------------------------------------
 Hash Right Join  (cost=67.60..113.50 rows=1360 width=32)
   Hash Cond: ((b.id)::text = (a.id)::text)
   ->  HashAggregate  (cost=27.00..40.60 rows=1360 width=32)
         Group Key: b.id
         ->  Seq Scan on b  (cost=0.00..23.60 rows=1360 width=32)
   ->  Hash  (cost=23.60..23.60 rows=1360 width=32)
         ->  Seq Scan on a  (cost=0.00..23.60 rows=1360 width=32)
(7 rows)
b)
create table a (id text primary key);
create table b (id text primary key);
explain   select a.*
     from a
left join (select distinct id from b) as b
       on a.id = b.id;
                      QUERY PLAN
------------------------------------------------------
 Seq Scan on a  (cost=0.00..23.60 rows=1360 width=32)
- Kim Carlsen
| From | Date | Subject | |
|---|---|---|---|
| Next Message | rob stone | 2017-09-16 20:20:21 | Re: looking for a globally unique row ID | 
| Previous Message | Rafal Pietrak | 2017-09-16 17:18:54 | Re: looking for a globally unique row ID | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andres Freund | 2017-09-16 20:27:05 | Re: Re: [COMMITTERS] pgsql: Perform only one ReadControlFile() during startup. | 
| Previous Message | Tom Lane | 2017-09-16 19:59:01 | Re: Re: [COMMITTERS] pgsql: Perform only one ReadControlFile() during startup. |