From: Greg Stark <gsstark@mit.edu>
To: Jared Carr <jared@89glass.com>
Cc: Greg Stark <gsstark@mit.edu>
Cc: pgsql-performance@postgresql.org
Subject: Re: A question on the query planner
Date: 02 Dec 2003 17:32:11 -0500
Message-ID: <87ptf697h0.fsf@stark.dyndns.tv> (raw)
In-Reply-To: <3FCCF61E.90307@89glass.com>
References: <3FCBB639.10409@89glass.com>
<1070385381.24915.8650.camel@camel>
<3FCCD225.8030609@89glass.com>
<87d6b79har.fsf@stark.dyndns.tv>
<3FCCE48B.10406@89glass.com>
<871xrn9e09.fsf@stark.dyndns.tv>
<3FCCF61E.90307@89glass.com>
Jared Carr <jared@89glass.com> writes:
> Greg Stark wrote:
>
> > Well it looks like you have something strange going on. What data type is
> > car_id in each table?
> >
> car_id is a varchar(10) in both tables.
Huh. The following shows something strange. It seems joining on two varchars
no longer works well. Instead the optimizer has to convert both columns to
text.
I know some inter-type comparisons were removed a while ago, but I would not
have thought that would effect varchar-varchar comparisons. I think this is
pretty bad.
test=# create table a (x varchar primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "a_pkey" for table "a"
CREATE TABLE
test=# create table b (x varchar primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "b_pkey" for table "b"
CREATE TABLE
test=# select * from a,b where a.x=b.x;
x | x
---+---
(0 rows)
test=# explain select * from a,b where a.x=b.x;
QUERY PLAN
------------------------------------------------------------------
Merge Join (cost=139.66..159.67 rows=1001 width=64)
Merge Cond: ("outer"."?column2?" = "inner"."?column2?")
-> Sort (cost=69.83..72.33 rows=1000 width=32)
Sort Key: (a.x)::text
-> Seq Scan on a (cost=0.00..20.00 rows=1000 width=32)
-> Sort (cost=69.83..72.33 rows=1000 width=32)
Sort Key: (b.x)::text
-> Seq Scan on b (cost=0.00..20.00 rows=1000 width=32)
(8 rows)
test=# create table a2 (x text primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "a2_pkey" for table "a2"
CREATE TABLE
test=# create table b2 (x text primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "b2_pkey" for table "b2"
CREATE TABLE
test=# explain select * from a2,b2 where a2.x=b2.x;
QUERY PLAN
-------------------------------------------------------------------
Hash Join (cost=22.50..57.51 rows=1001 width=64)
Hash Cond: ("outer".x = "inner".x)
-> Seq Scan on a2 (cost=0.00..20.00 rows=1000 width=32)
-> Hash (cost=20.00..20.00 rows=1000 width=32)
-> Seq Scan on b2 (cost=0.00..20.00 rows=1000 width=32)
(5 rows)
--
greg
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: gsstark@mit.edu, jared@89glass.com
Subject: Re: A question on the query planner
In-Reply-To: <87ptf697h0.fsf@stark.dyndns.tv>
* 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