D
D
Dmitry2015-07-17 19:28:42
SQL
Dmitry, 2015-07-17 19:28:42

Are these queries fast?

Guys, tell me if there is a difference in efficiency in these two queries, and if so, what is it? what request on idea should work faster?
first request

select *
from Table1 t1 inner join (select tt.someId from TestTable tt where tt.id > 100) t2 on t1.someId = t2.someId
where t1.id > 1000

second request
select *
from Table t1 inner join TestTable t2 on t1.someId = t2.someId
where t1.id > 1000 and t2.id > 100

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-07-17
@Nipheris

For a normal scheduler, the behavior specifically for these two requests should be the same. In any case, before the nested join loop, you will need to filter the rows of both tables by indexes. Because The filtering conditions for both tables are independent, I can't even think of how to run the queries differently.
In general, the second option is much clearer for both the programmer and the DBMS (it is easier to build an execution plan).

R
Rsa97, 2015-07-17
@Rsa97

Compare query plans (EXPLAIN), most likely there will be no difference.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question