Solved

Interbase optimizing SQL Query

Posted on 2002-07-09
7
478 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
Comment Utility
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
Comment Utility
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
Comment Utility
In this case, whch coloumns should i use ?
ART      (in Where)
DATUM    (in Where and Order)
OTHER_ID (in JOIN)     ?????
PARETID  (in Order)    ?????
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Accepted Solution

by:
YodaMage earned 68 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now