Inner join vs Where

后端 未结 19 1046
庸人自扰
庸人自扰 2020-11-22 05:20

Is there a difference in performance (in oracle) between

Select * from Table1 T1 
Inner Join Table2 T2 On T1.ID = T2.ID

And



        
相关标签:
19条回答
  • 2020-11-22 06:04

    They should be exactly the same. However, as a coding practice, I would rather see the Join. It clearly articulates your intent,

    0 讨论(0)
  • 2020-11-22 06:06

    Functionally they are the same as has been said. I agree though that doing the join is better for describing exactly what you want to do. Plenty of times I've thought I knew how I wanted to query something until I started doing the joins and realized I wanted to do a different query than the original one in my head.

    0 讨论(0)
  • 2020-11-22 06:06

    They're both joins and where that do the same thing.

    Give a look at In MySQL queries, why use join instead of where?

    0 讨论(0)
  • 2020-11-22 06:07

    If the query optimizer is doing its job right, there should be no difference between those queries. They are just two ways to specify the same desired result.

    0 讨论(0)
  • 2020-11-22 06:12

    No! The same execution plan, look at these two tables:

    CREATE TABLE table1 (
      id INT,
      name VARCHAR(20)
    );
    
    CREATE TABLE table2 (
      id INT,
      name VARCHAR(20)
    );
    

    The execution plan for the query using the inner join:

    -- with inner join
    
    EXPLAIN PLAN FOR
    SELECT * FROM table1 t1
    INNER JOIN table2 t2 ON t1.id = t2.id;
    
    SELECT *
    FROM TABLE (DBMS_XPLAN.DISPLAY);
    
    -- 0 select statement
    -- 1 hash join (access("T1"."ID"="T2"."ID"))
    -- 2 table access full table1
    -- 3 table access full table2
    

    And the execution plan for the query using a WHERE clause.

    -- with where clause
    
    EXPLAIN PLAN FOR
    SELECT * FROM table1 t1, table2 t2
    WHERE t1.id = t2.id;
    
    SELECT *
    FROM TABLE (DBMS_XPLAN.DISPLAY);
    
    -- 0 select statement
    -- 1 hash join (access("T1"."ID"="T2"."ID"))
    -- 2 table access full table1
    -- 3 table access full table2
    
    0 讨论(0)
  • 2020-11-22 06:13

    Using JOIN makes the code easier to read, since it's self-explanatory.

    There's no difference in speed(I have just tested it) and the execution plan is the same.

    0 讨论(0)
提交回复
热议问题