Giter Club home page Giter Club logo

Comments (5)

hsyuan avatar hsyuan commented on July 18, 2024

because the return type of count is bigint, not int.

from gporca.

hsyuan avatar hsyuan commented on July 18, 2024

maybe similar with #50

from gporca.

hsyuan avatar hsyuan commented on July 18, 2024

simpler repro:

create table foo(a int, b int) distributed by (a);
create table bar(c bigint, d bigint) distributed by (c);

set optimizer=off;
explain select * from foo, bar where a = c;
                                   QUERY PLAN
--------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=1.02..990.66 rows=72 width=24)
   ->  Hash Join  (cost=1.02..990.66 rows=24 width=24)
         Hash Cond: bar.c = foo.a
         ->  Seq Scan on bar  (cost=0.00..811.00 rows=23700 width=16)
         ->  Hash  (cost=1.01..1.01 rows=1 width=8)
               ->  Seq Scan on foo  (cost=0.00..1.01 rows=1 width=8)
 Settings:  optimizer=off
 Optimizer status: legacy query optimizer
(8 rows)

set optimizer=on;
explain select * from foo, bar where a = c;
                                              QUERY PLAN
------------------------------------------------------------------------------------------------------
 Gather Motion 3:1  (slice2; segments: 3)  (cost=0.00..862.00 rows=1 width=24)
   ->  Hash Join  (cost=0.00..862.00 rows=1 width=24)
         Hash Cond: bar.c = foo.a::bigint
         ->  Table Scan on bar  (cost=0.00..431.00 rows=1 width=16)
         ->  Hash  (cost=431.00..431.00 rows=1 width=8)
               ->  Redistribute Motion 3:3  (slice1; segments: 3)  (cost=0.00..431.00 rows=1 width=8)
                     Hash Key: foo.a::bigint
                     ->  Table Scan on foo  (cost=0.00..431.00 rows=1 width=8)
 Settings:  optimizer=on
 Optimizer status: PQO version 2.51.0
(10 rows)

from gporca.

micklf avatar micklf commented on July 18, 2024

join:
varchar -> broadcast
text -> hashjoin

It is the same situation in legacy optimizer, not only in orca

create table test5(
col1 numeric(20,0),
col2 character varying(32) NOT NULL
)WITH (
  OIDS=FALSE
)
DISTRIBUTED BY (col2);

create table test6(
col1 numeric(20,0),
col2 character varying(32) NOT NULL
)WITH (
  OIDS=FALSE
)
DISTRIBUTED BY (col2);


insert into test5 values(1,'1'),(2,'2'),(3,'3'),(4,'4'),(5,'5');
insert into test6 values(1,'1'),(2,'2'),(3,'3'),(4,'4'),(5,'5');

db1=# explain select * from test5, test6 where test5.col2=test6.col2;
                                           QUERY PLAN                                            
-------------------------------------------------------------------------------------------------
 Gather Motion 2:1  (slice2; segments: 2)  (cost=2.32..4.46 rows=5 width=18)
   ->  Hash Join  (cost=2.32..4.46 rows=3 width=18)
         Hash Cond: test5.col2::text = test6.col2::text
         ->  Seq Scan on test5  (cost=0.00..2.05 rows=3 width=9)
         ->  Hash  (cost=2.20..2.20 rows=5 width=9)
               ->  Broadcast Motion 2:2  (slice1; segments: 2)  (cost=0.00..2.20 rows=5 width=9)
                     ->  Seq Scan on test6  (cost=0.00..2.05 rows=3 width=9)
(7 rows)

from gporca.

hsyuan avatar hsyuan commented on July 18, 2024

But orca generated plan without broadcast motion:

explain select * from test5, test6 where test5.col2=test6.col2;
                                  QUERY PLAN
-------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..862.00 rows=5 width=18)
   ->  Hash Join  (cost=0.00..862.00 rows=2 width=18)
         Hash Cond: test5.col2::text = test6.col2::text
         ->  Table Scan on test5  (cost=0.00..431.00 rows=2 width=9)
         ->  Hash  (cost=431.00..431.00 rows=2 width=9)
               ->  Table Scan on test6  (cost=0.00..431.00 rows=2 width=9)
 Settings:  optimizer=on
 Optimizer status: PQO version 2.51.3
(8 rows)

from gporca.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.