If you use OR logical operation to find rows from a MS SQL 6.5
table, and there is index on the field for which values you use OR
operation, then MS SQL 6.5 can use worktable with dynamic index
on searchable field instead simple index search. You can check it by
setting SET SHOWPLAN ON. So, if the table is very big, it can take
a lot of time. This is the example of simple table creation and addition
of new rows into this table:
|
If you want to find all rows from the table TestTable where f2 = ‘100’
or f2 = ‘500’, you can use the following select statement:
|
You can increase the speed of this query by divide it into to select
statement and union this statements with UNION ALL operator. For each
query the appropriate index will be used, and this way can increase
the speed of the new select statement in several times in comparison
with the first one.
There are physical read and logical read operations. A logical read occurs
if the page is currently in the cache. If the page is not currently in the
cache, a physical read is performed to read the page into the cache.To see
how many logical or physical read operations were made, you can use
SET STATISTICS IO ON command. This is the example:
|
These are the results:
|