|
|
|
Простой "детский" вопрос по индексам
|
|||
|---|---|---|---|
|
#18+
Вопрос скорее по теории. Дело в том, что об индексах я знаю только то, что "их надо использовать везде, на тех стобцах, по которым будет происходить наиболее частый отбор" (если что не так- не пеняйте, лучше ссылкой.. :-) Есть таблица по типу: Код: plaintext 1. 2. 3. 4. 5. Таблица практически не будет ни INSERT-иться ни UPDATE-еться, то есть служить исключительно для выборки. При чем запросы будут идти по всем столбцам: Код: plaintext 1. 2. Вопрос: есть ли смысл создавать индексы на каждый из столбцов с целью ускорить выбрку? Заранее спасибо. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2002, 13:07:41 |
|
||
|
Простой "детский" вопрос по индексам
|
|||
|---|---|---|---|
|
#18+
Если в таблице больше нескосльких тычяч записей, то имеет смысл использовать индексы. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2002, 13:14:53 |
|
||
|
Простой "детский" вопрос по индексам
|
|||
|---|---|---|---|
|
#18+
Avoid using variables in the WHERE clause of a query located in a batch file. Let's find out why this may not be a good idea. First, let's look at the following code: SELECT employee_id FROM employees WHERE age = 30 and service_years = 10 Assuming that both the age and the service_years columns have indexes, and the table has many thousands of records, then SQL Server's Query Optimizer will select the indexes to perform the query and return results very quickly. Now, let's look at the same query, but written to be more generic, one that you might find in a generic batch file: DECLARE @age int SET @age = "30" DECLARE @service_years int SET @service_years = "10" SELECT employee_id FROM employees WHERE age = @age and service_years = @service_years When the above code is run, even though both the age and the service_years columns have indexes, they may not be used, and a table scan may be used instead, potentially greatly increasing the amount of time for the query to run. The reason the indexes may not be used is because the Query Analyzer does not know the value of the variables when it selects an access method to perform the query. Because this is a batch file, only one pass is made of the Transact-SQL code, preventing the Query Optimizer from knowing what it needs to know in order to select an access method that uses the indexes. If you cannot avoid using variables in the WHERE clauses of batch scripts, consider using an INDEX query hint to tell the Query Optimizer to use the available indexes instead of ignoring them and performing a table scan. This of course that the indexes are highly selective. If the indexes are not highly selective, then a table scan most likely be more efficient than using the available indexes. Another option is to not use a script, but a stored procedure instead. Variables in stored procedures don't cause the problem described above. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.11.2002, 13:39:35 |
|
||
|
|

start [/forum/topic.php?fid=46&msg=32064934&tid=1819070]: |
0ms |
get settings: |
6ms |
get forum list: |
9ms |
check forum access: |
2ms |
check topic access: |
2ms |
track hit: |
43ms |
get topic data: |
7ms |
get forum data: |
2ms |
get page messages: |
26ms |
get tp. blocked users: |
1ms |
| others: | 203ms |
| total: | 301ms |

| 0 / 0 |
