Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Interbase optimizing SQL Query

Posted on 2002-07-09
7
Medium Priority
?
530 Views
Last Modified: 2013-12-09
I use Interbase 6.01 and Firebird
and have following sql code

What indexes do i need for otimizing this code ?
I have over a half million of rows in this table ?

Is it better to use one index with many columns or generate for every column an individual index ? Whats better for speed and size ?

'SELECT A.ID, A.AUFTRAGID, A.TEILID, A.DATUM, A.PARENTID, A.DAUER, '+
        ' M.PARENTID AS MASCHINE '+
        ' FROM AUFTRAG_KOSTEN A '+
        ' LEFT OUTER JOIN AUFTRAG_KOSTEN M ON M.ID = A.OTHER_ID '+
        ' WHERE A.ART = 0 AND A.DATUM >= :VON AND A.DATUM < :BIS ORDER BY A.PARENTID, A.DATUM'
0
Comment
Question by:Dev6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Assisted Solution

by:thegroup
thegroup earned 264 total points
ID: 7144217
if you generate several index they can be freely combined to achieve the best results.

the recomended candidates to index are condition fields (where...) and join fields (they are conditions too)

perhaps you don't need to index all of them but only those with more records.

(an active index slow down insertions and deletes and updates, be careful)
0
 
LVL 4

Expert Comment

by:YodaMage
ID: 7144219
case 1 : Create Index Index1 On table1 (field1, field2, field3)

case 2 :   Create Index Index1 On table1 (field1)
            Create Index Index2 On table1 (field2)
            Create Index Index3 On table1 (field3)

Case 1 will be more efficient *if* you only
ever do queries which reference all three columns in the WHERE clause. Otherwise choose case 2.

0
 

Author Comment

by:Dev6
ID: 7145340
In this case, whch coloumns should i use ?
ART      (in Where)
DATUM    (in Where and Order)
OTHER_ID (in JOIN)     ?????
PARETID  (in Order)    ?????
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
YodaMage earned 272 total points
ID: 7146190
In your case I would think an index of (PARETID, DATUM, ART), though to be sure, try that index, then time query, then do it as 3 seperate indexes, and again time query.  
0
 
LVL 1

Assisted Solution

by:grolschisgood
grolschisgood earned 264 total points
ID: 8221504
A.OTHER_ID
A.ART
A.DATUM

you will need indexes on the above fields that are used int he join and where clause.  An index on fields int he order cluase will be off no benefit.

Also do not index any of the above fields if they contain a small set of distinct values.  eg if A.ART only contain values 0 and 1 then an index on this field will be off no use.

You also do not need to index primary key fields as they already have an index.  therefore you should not need an index on  M.ID as this appears to be a primary key.

you should create a seperate index for each field for maximum flexibility, however you could create a single index for A.OTHER_ID, and a single index containing both A.ART and A.DATUM. (rem exclude A.ART if it does not have many distinct values)

Also note the more indexes you have the slower it is to INSERT data into the table, so dont go crazy on indexes that are not needed.

k
cam
0
 
LVL 10

Expert Comment

by:kacor
ID: 9824623
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
       to split points as follows:
                 66 points for thegroup
                 66 points for grolschisgood
                 67 points for YodaMage
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

kacor
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question