Solved

SPEEDING UP QUERY OR READING FROM A SINGLE TABLE

Posted on 1998-02-04
1
148 Views
Last Modified: 2010-04-04
I have a large database program that is really slow on querying because it is reading from multiple tables and using a tree to list the information. How can I speed this up or get it to read from a single table to speed it up?  I here is the code I am currently using.


var
   curNode : TTreeNode;
begin
   // Make sure report printing is disabled until a unit is selected
   mnuRepFeatures.Enabled:=false;
   mnuRepSpec.Enabled:=false;
   mnuPartIllus.Enabled:=false;
   mnuRepWriteup.Enabled:=false;
   mnuPartXRef.Enabled:=false;

   // Query Statuses set to false
   eqpSpecIllusQryStatus:=False;
   eqpSpecFeatureQryStatus:=False;
   eqpSpecDetailQryStatus:=False;
   partIllusQryStatus:=False;
   partKeysQryStatus:=False;
   writeupDetailQryStatus:=False;
   // TODO WSL Exception Handle
   curNode := seriesTreeView.Selected;
   pgctrlEqpDetail.ActivePage := tsCover;
   if (curNode.ImageIndex = 0) then
     pnlDescription.Caption := curNode.Text
   else
    begin
      pnlEqpDescription.Caption := curNode.Text;
      mnuRepFeatures.Enabled:=true;
      mnuRepSpec.Enabled:=true;
      mnuPartIllus.Enabled:=true;
      mnuRepWriteup.Enabled:=true;
      mnuPartXRef.Enabled:=false;
    end;
   StatusBar1.Panels[1].Text := curNode.Text;
   StatusBar1.Repaint;
   nbEqpDetail.PageIndex := curNode.ImageIndex;
end;

procedure TfrmMain.ExpandClick(Sender: TObject);
var
   tmpTreeNode : TTreeNode;
begin
   tmpTreeNode := seriesTreeView.Selected;
   if not (tmpTreeNode = nil) then
      tmpTreeNode.Expand(False);
end;

procedure TfrmMain.CollapseClick(Sender: TObject);
var
   tmpTreeNode : TTreeNode;
begin
   tmpTreeNode := seriesTreeView.Selected;
   if not (tmpTreeNode = nil) then
      tmpTreeNode.Collapse(False);
end;

procedure TfrmMain.FormShow(Sender: TObject);
var
   i : integer;
   d : double;
begin
   if (firstTime=false) then
      exit;
   firstTime:=false;
   strQueryStatus := 'Querying...';
   // Adjust column size to fit
   d := dbGridSpec.Width / 2.;
   i := Round(d);
   dbGridSpec.Columns.Items[0].Width:=i;
   dbGridSpec.Columns.Items[1].Width:=i;


Please answer ASAP....
0
Comment
Question by:aj85
1 Comment
 
LVL 3

Accepted Solution

by:
d4jaj1 earned 100 total points
ID: 1358252
Here's what I would suggest, use a TTable instead of a query.  If you have an index on teh table, use teh setRange function, as it is much faster that teh TQuery.  Furthermore, youshould speed things up with the table by opening it in exclusive mode. This way, teh BDE doesn't have to worry about periodically checking if other DB's need access.

If there is some reason you have to use a query (which I can't tell from your code), use the ORDER BY clause.  This will force teh query to use the available indexes. You must list the fields in the ORDER BY as they appear as indexes.  For example, if you have an index for FirstName-LastName, your ORDER BY clause must look like "ORDER BY FirstName, LastName;" for teh index to be used.  This is the only way (other than making sound your relationships are set up correctly) to speed up a query.

Any questions, please add a comment.  Good Luck!

Jay
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 166
Internet Explorer View Settings Question 15 116
Installshield for Embarcadero EX 10.1 Berlin 4 60
Firemonkey BASS_Init into a thread 17 30
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

860 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