473,379 Members | 1,245 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Learning about Indexes the Hard Way

Hello, I am experimenting with indexes and hope people can shed light
on some of my problems.
I am using SLQ 2000 on Win 2000 Server. Using the following query for
discussion;
--------------------------------
SELECT TOP 1000000
E.EUN_Numeric, -- Primary Key
E.EUN_CODE, -- VarChar
E.[timestamp] --,
--E.Model -- Computed column (substring of EUN_CODE)
FROM dbo.Z1_EUNCHK E
--WHERE E.[timestamp]DATEADD ( wk , -48, getdate() ) AND
-- E.[timestamp]< DATEADD ( wk , -4, getdate() )
ORDER BY E.[timestamp] DESC
-----------------------------------

Problem 1) If I set up a single Index on the TimeStamp (plus the PK on
EUN_Numeric) then there is not improvement in performance.
It is only when I set up an Index on the Timestamp,EUN_Numeric,EUN_Code
then I get a good improvement. This is also the
case with the "where" clause added. I am using query analyser. The
improvement is 14 secs to 3 secs (mainly with the removal of the sort
process)

Why?
My expectation is that if my query uses [timestamp] column then surely
an index only on this is adequate.

Problem 2) Introducing the simple computed column into the query takes
the time to 15 secs (with Sort processes involved).

Why does revert back to sorting process when previous the index was
used ?
Regards JC......

Oct 18 '06 #1
6 1519
Jim,

In query analyzer there is a handy dandy visual tool - "show execution
plan"

If you have not already, you should select this option and run your
query both ways to review the plan. By hovering over the icons in the
result, you can see if the index is used.

You can also investigate the use of SHOWPLAN which can give you a text
result.

I believe also that you may be experiencing some caching effect where
the second time you run a query it will run faster because the plan has
been cached from the first run.
ji**********@gm.com wrote:
Hello, I am experimenting with indexes and hope people can shed light
on some of my problems.
I am using SLQ 2000 on Win 2000 Server. Using the following query for
discussion;
--------------------------------
SELECT TOP 1000000
E.EUN_Numeric, -- Primary Key
E.EUN_CODE, -- VarChar
E.[timestamp] --,
--E.Model -- Computed column (substring of EUN_CODE)
FROM dbo.Z1_EUNCHK E
--WHERE E.[timestamp]DATEADD ( wk , -48, getdate() ) AND
-- E.[timestamp]< DATEADD ( wk , -4, getdate() )
ORDER BY E.[timestamp] DESC
-----------------------------------

Problem 1) If I set up a single Index on the TimeStamp (plus the PK on
EUN_Numeric) then there is not improvement in performance.
It is only when I set up an Index on the Timestamp,EUN_Numeric,EUN_Code
then I get a good improvement. This is also the
case with the "where" clause added. I am using query analyser. The
improvement is 14 secs to 3 secs (mainly with the removal of the sort
process)

Why?
My expectation is that if my query uses [timestamp] column then surely
an index only on this is adequate.

Problem 2) Introducing the simple computed column into the query takes
the time to 15 secs (with Sort processes involved).

Why does revert back to sorting process when previous the index was
used ?
Regards JC......
Oct 18 '06 #2
I have been using display execution plan (of query analyser). This is
how I known if the task performed in 'top', 'sort', 'seek' and 'index
scan'. These tasks I correlate with durations taken.

So the questions still remain;
Problem 1) Why is the smaller index only involving 'timestamp' not used
when it's available and covers the details on the query involved ?

Problem 2) Why does the introduction of a simple computed column
dis-able the optimiser?

Regards JC.......

Oct 19 '06 #3
The variation in time may result from how the data is physically
arrranged on disk, plus the effect of a covering index.

The index {timestamp, eun_numeric, eun_code} is arranged by timestamp,
so it's very quick to search on that basis, plus it contains all the
information needed for the query -- so when it is used, the table
itself isn't even examined.

Using only the index on {timestamp} requires that the table itself be
accessed in order to get the values of eun_numeric and eun_code.
Depending on how the PK eun_numeric is ordered, the query might end up
jumping around all over the disk to locate the data.

Jim G

ji**********@gm.com wrote:
Hello, I am experimenting with indexes and hope people can shed light
on some of my problems.
I am using SLQ 2000 on Win 2000 Server. Using the following query for
discussion;
--------------------------------
SELECT TOP 1000000
E.EUN_Numeric, -- Primary Key
E.EUN_CODE, -- VarChar
E.[timestamp] --,
--E.Model -- Computed column (substring of EUN_CODE)
FROM dbo.Z1_EUNCHK E
--WHERE E.[timestamp]DATEADD ( wk , -48, getdate() ) AND
-- E.[timestamp]< DATEADD ( wk , -4, getdate() )
ORDER BY E.[timestamp] DESC
-----------------------------------

Problem 1) If I set up a single Index on the TimeStamp (plus the PK on
EUN_Numeric) then there is not improvement in performance.
It is only when I set up an Index on the Timestamp,EUN_Numeric,EUN_Code
then I get a good improvement. This is also the
case with the "where" clause added. I am using query analyser. The
improvement is 14 secs to 3 secs (mainly with the removal of the sort
process)

Why?
My expectation is that if my query uses [timestamp] column then surely
an index only on this is adequate.

Problem 2) Introducing the simple computed column into the query takes
the time to 15 secs (with Sort processes involved).

Why does revert back to sorting process when previous the index was
used ?
Regards JC......
Oct 19 '06 #4

ji**********@gm.com wrote:
I have been using display execution plan (of query analyser). This is
how I known if the task performed in 'top', 'sort', 'seek' and 'index
scan'. These tasks I correlate with durations taken.

So the questions still remain;
Problem 1) Why is the smaller index only involving 'timestamp' not used
when it's available and covers the details on the query involved ?
But it doesn't cover the details required (using the word cover as in
the phrase covering index), because it doesn't include all columns
which are included in the select list.

So becuase the optimiser know's it's going to have to go into the
clustered index anyway (especially with no where clause), it just uses
it instead.
Problem 2) Why does the introduction of a simple computed column
dis-able the optimiser?

Regards JC.......
I don't believe the optimiser can break down a computed column to know
which underlying columns it is based upon. So it doesn't know that the
computed column is "covered" by a particular index. Of course, you can
index computed columns, and it might then use that index, if it was a
covering index.

Damien

Oct 19 '06 #5
How can this be true? In this case, the computed column is simply
a substring of one of the other columns that is already in the query,
and is also included in the 3-item index. Is this really too hard for
the
optimizer?
I don't believe the optimiser can break down a computed column to know
which underlying columns it is based upon. So it doesn't know that the
computed column is "covered" by a particular index. Of course, you can
index computed columns, and it might then use that index, if it was a
covering index.

Damien
Oct 20 '06 #6
ji**********@countrywide.com wrote:
Damien Wrote:
I don't believe the optimiser can break down a computed column to know
which underlying columns it is based upon. So it doesn't know that the
computed column is "covered" by a particular index. Of course, you can
index computed columns, and it might then use that index, if it was a
covering index.

Damien
How can this be true? In this case, the computed column is simply
a substring of one of the other columns that is already in the query,
and is also included in the 3-item index. Is this really too hard for
the
optimizer?
In the *very specialised* situation where the computed column is the
leftmost n characters, then the index would be usable. But why should
the good people writing the optimizer spend time on that particular
condition? In all other substring situations (where you do not start at
the leftmost character), and for any more complex calculated columns
(remember, they can reference any of the columns), the index would be
useless.

And you always have the option, if you need an index to be considered,
of indexing the computed column.

Damien

Oct 24 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Angela | last post by:
As a former C++ programmer I picked up on C# rather quickly, you probably will too. I did buy a reference book though to help me out. I'm a fan of the Wrox books, so I bought Professional C#...
2
by: Mike Ruskai | last post by:
I've searched Google every way I know how, and came up with two answers that refer to MAX_KEY and MI_MAX_KEY, along with a typedef for key_map. I have the 4.1.1 alpha source (4.0 is no good,...
3
by: Randell D. | last post by:
Folks, My internet access is intermitent until I get my own connection inside the next ten days - I say this so that I can thank in advance who ever gives a few seconds to read/answer my...
8
by: scorpion53061 | last post by:
Hi, I am a vb.net guy......(I know boo hiss LOL) I was thinking of learning C# as well. Can I expect a hard road of it as far as a learning curve? As as side note, what made you choose...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
36
by: utab | last post by:
Dear, I have experince in C( numerical projects, like engineering problems, scientific applications) I have the basic notion of C++ also, I have read Accelerated C++ until Chapter 7, however it...
1
by: Curt | last post by:
What is the difference please?
78
by: arnuld | last post by:
hai all, i am standing on a "crossroad to C++". I am here in front of you as i have a problem. i will be brief. Please do not think: "arnuld is sick", i am really struggling & doing hard-work to...
8
by: Jeff | last post by:
I have an array; $array = 'something'; $array = 'something else'; I can do this: echo $array; And I can do this: $content =<<<content
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.