Re: A question on the query planner
От | Greg Stark |
---|---|
Тема | Re: A question on the query planner |
Дата | |
Msg-id | 87ptf697h0.fsf@stark.dyndns.tv обсуждение исходный текст |
Ответ на | Re: A question on the query planner (Jared Carr <jared@89glass.com>) |
Ответы |
Re: A question on the query planner
Re: A question on the query planner |
Список | pgsql-performance |
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
В списке pgsql-performance по дате отправления: