Solved

Interbase optimizing SQL Query

Posted on 2002-07-09
7
487 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
7 Comments
 
LVL 1

Assisted Solution

by:thegroup
thegroup earned 66 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 4

Accepted Solution

by:
YodaMage earned 68 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 66 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now