Solved

SPEEDING UP QUERY OR READING FROM A SINGLE TABLE

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

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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