Question about joining the table

When joining between tables (as in the examples below), is there a difference in efficiency between joining tables or joining subqueries containing only the columns you need?

In other words, is there a difference in performance between the two tables?

SELECT result
  FROM result_tbl
  JOIN test_tbl                    USING (test_id)
  JOIN sample_tbl                  USING (sample_id)
  JOIN (SELECT request_id
          FROM request_tbl
         WHERE request_status='A') USING(request_id)

vs

SELECT result
  FROM (SELECT result,  test_id   FROM result_tbl)
  JOIN (SELECT test_id, sample_id FROM test_tbl)   USING(test_id)
  JOIN (SELECT sample_id          FROM sample_tbl) USING(sample_id)
  JOIN (SELECT request_id
          FROM request_tbl
         WHERE request_status='A')                 USING(request_id)
+3
source share
3 answers

It does not matter. Actually, it can be WORSE, because you take control from the optimizer, who usually knows best.

, JOIN , EXISTS-, , . ( ) , .

.

SELECT t1.id1
  FROM table1 t1
 INNER JOIN table2 ON something = something

SELECT id1
  FROM table1 t1
 WHERE EXISTS( SELECT *
                 FROM table2
                WHERE something = something )

. .

, , :

JOIN (SELECT request_id         FROM request_tbl        WHERE request_status = 'A')

SELECT result
  FROM request
 WHERE EXISTS(...)
   AND request_status = 'A'
+4

- , . , , : .

+5

.

, EXPLAIN PLAN - Oracle , , , "", - , .

Oracle "" (.. ), , , ; Oracle "", .

, , "", ( ), Oracle , ( "" , "test_id" ) .

+2

Source: https://habr.com/ru/post/1708198/


All Articles