Что быстрее В или ИЛИ?

У меня создалось впечатление, что весь код c является допустимым кодом C++.

6
задан chaos 13 July 2009 в 14:41
поделиться

9 ответов

"IN" will be translated to a series of "OR"s...if you look at the execution plan for a query with "IN", you'll see it has expanded it out.

Much cleaner to use "IN" in my opinion, especially in larger queries it makes it much more readable.

11
ответ дан 8 December 2019 в 02:27
поделиться

Don't think; profile.

I urge you not to rely on intuition, yours or anyone else's, when considering questions of speed. Instead, try both options, with some kind of profiling/run time measurement, and find out which is faster in your circumstances.

14
ответ дан 8 December 2019 в 02:27
поделиться

they should generate the same exact plan from my experience

take a look at the plan

2
ответ дан 8 December 2019 в 02:27
поделиться

Write two stored procedures, one using IN, the other using OR, on a test server. Run each procedure 10,000 (or 1,000,000, or whatever) times, and compare the timings.

In general, this is pretty much the "only" way to have a good answer to the question of which approach is faster: write simple timing test cases, and run them many, many times.

4
ответ дан 8 December 2019 в 02:27
поделиться

In SQL Server, the optimizer will generate identical plans for these queries.

3
ответ дан 8 December 2019 в 02:27
поделиться

If A is a computation, it will be performed once using IN and N times using OR.

1
ответ дан 8 December 2019 в 02:27
поделиться

Regardless of whether or not A is a computation or column, looks like SQL Server 2005 converts IN to OR clauses.

1
ответ дан 8 December 2019 в 02:27
поделиться

Самым быстрым в SQL Server является использование DELETE с ВНУТРЕННЕЕ СОЕДИНЕНИЕ. С тремя значениями вы не заметите разницы, но с большим количеством значений (мы делаем несколько тысяч) разница феноменальна. Вы можете спрятать свои значения во временную таблицу, а затем присоединиться к ней.

Например,

DELETE C
FROM Customer AS C INNER JOIN #ValuesToDelete AS D ON C.CustID = D.CustID

Вы также можете добавить необязательное предложение where.

1
ответ дан 8 December 2019 в 02:27
поделиться

It must be exactly equals. Most of RDMBS transalte IN to ORs.

Of course, if you consider the translation from INs to ORs to be high time consuming, the sentence with ORs is faster ;-)

Update: I'm considering that A is a column.

0
ответ дан 8 December 2019 в 02:27
поделиться
Другие вопросы по тегам:

Похожие вопросы: