?
Solved

Interbase optimizing SQL Query

Posted on 2002-07-09
7
Medium Priority
?
520 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
Independent Software Vendors: 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

Independent Software Vendors: 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!

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this article, we’ll look at how to deploy ProxySQL.
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

801 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