Solved

SPEEDING UP QUERY OR READING FROM A SINGLE TABLE

Posted on 1998-02-04
1
146 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

23 Experts available now in Live!

Get 1:1 Help Now