473,326 Members | 2,133 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,326 software developers and data experts.

Need guidelines for INDEXING database table

I am developing a "Local business search" website, just like
OLX, JUSTDIAL or QUIKR...etc.

Since its a search based site (i.e. read intensive website),
I have to ensure that search data get retrieved quickly and efficiently. That's why I have decided to use INDEXING on tables.

I would like to use INDEXING on "ADVERTISEMENT" table, because all the search data will be retrieved from this table.

I need some guidance on using indexes.
1. on which columns should I use indexing
2. which type should I use "Clustered/non clustered".

I am aware of the fact that using Indexes is a ticky process and we have to ensure that they are used on proper columns and tables are not over-indexed.

Below are the important tables and their corresponding columns

1. ADVERTISMENT TABLE (Columns mentions as below):
AdvID
CategoryID -- (referenced from category table)
SubCatID -- (referenced from subcategory table)
Adv_PlanID -- (referenced from Adv. plans table)
UserID -- (referenced from Adv. Users table)
Adv_Desc -- (This text will be searched by user)
CreateDate
Adv_Status
Expire_Date
LocationID
StateID
CityID

2. Categories Table
Category_ID
Category _Description

3. Sub Category Table
SubCategory_ID
Category_ID (Referenced from Category table)
SubCatDescription

so on...

Thanks In Advance...
Aug 7 '13 #1
3 1587
I hope these guidelines may help you.

Always look at the query plan first. It will show you the optimal current execution plan from the query engine's point of view. Find the most expensive part of the execution plan and start optimizing from there.

If you see table scan, optimize. Table scan is the slowest possible way of execution. Table scan means not only that no index is used, but that there is no clustered index for this table at all. Even if you can only replace table scan with clustered index scan, it is still worth it.
If you see clustered index scan, find out whether it can be replaced with index seek. For that, find what conditions are applied to this table. Usually, conditions exist for two or three fields of the table.

Find out the most selective condition (that is, the condition that would produce the smallest number of records if applied alone), and see whether an index on this field exists.

Any index that lists this field first will qualify. If there is no such index, create it and see whether the query engine picks it up.
If the query engine is not picking up the existing index (that is, if it is still doing a clustered index scan), check the output list. It is possible that seek on your index is faster than clustered index scan, but involves bookmark lookup that makes the combined cost greater than use of a clustered index.
Clustered index operations (scan or seek) never need bookmark lookup, since a clustered index already contains all the data.

If the output list is not big, add those fields to the index, and see whether the query engine picks it up. Please remember that the combined size is more important than the number of fields. Adding three integer fields to the index is less expensive than adding one varchar field with an average data length of 20.

Try to make your index covering, and see whether it works better than clustered index scan. Please note that it is not always possible to make the query engine pick up your index automatically. A small table or a low-selectivity index will produce clustered index scan, even if your index is covering.
If you see bookmark lookup, it means that your index is not covering. Try to make it covering if it makes sense.

The execution plan selected by the query engine may be not the best one. The query engine makes certain assumptions about disk subsystem and CPU cost versus IO cost. These assumptions sometimes can be incorrect. If you don't believe that the query engine's selection is the best one, run a query in the loop for 10 to 15 minutes with automatic selection, change the query to use your index (you will have to use index hint to force it), and then run it for 10 to 15 minutes again. Compare the results to see which one works better.

Regards
Basanth
Aug 7 '13 #2
ck9663
2,878 Expert 2GB
Good advice Basanth...

Always remember, if you will create one index on a table, make it a clustered one.


Happy Coding!!!

~~ CK
Aug 7 '13 #3
Hi, thanks for answer, much depreciated.
Aug 10 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Martin Lucas-Smith | last post by:
Can anyone point me to a regular expression in PHP which could be used to check that a proposed (My)SQL database/table/column name is valid, i.e. shouldn't result in an SQL error when created? ...
3
by: I Are Confused | last post by:
I am trying to open Database #2 while in Database #1 and delete a table that is in #2 so that I can copy a table from #1 into #2 - all through a function. My Database #2, as part of the start up,...
1
by: jan | last post by:
Hello, I am new to this list and would appreciate some help with Access 2000 and Access 2003. I need to export our access database table statements by access database to place into our database...
8
by: David | last post by:
Hi, Could someone please xplain how to add a field to an existing SQL table in VB.Net I have added the field in the Server Explorer and it shows up when I reload the program but I cannot...
3
by: nvx | last post by:
Hello everyone... Just for the record, I'm a newbie to this data binding thing... In my C# application I need to bind a cell of an Access database table to a multiline TextBox. How should I do...
3
by: Rich Shepard | last post by:
I need to learn how to process a byte stream from a form reader where each pair of bytes has meaning according to lookup dictionaries, then use the values to build an array of rows inserted into a...
4
by: Amar | last post by:
Hi All, I need to select data from a database table containing huge amount of data. Now I am storing data using one primary key and I am just using simple select statement, and this process...
4
by: aakbar | last post by:
Hello every body, I need some clarification of concept regarding self referential tables. consider we have a "Person" table that stores data about employees of an organisation. in case a...
5
by: =?Utf-8?B?Y2RiaWdncw==?= | last post by:
Hi, I've been tasked to write a windows app that allows people to enter transactions. For each transaction, there can be an unknown number of items, and as a person enters an item, the program...
2
by: AquarianMermaid | last post by:
how to count the occurence of a particular word in search of an indexing database server
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.