Solved

Can I speed up these queries

Posted on 2011-03-09
3
242 Views
Last Modified: 2012-05-11
I have been working in many different access 2003 databases all with a SQL2000 backend with linked tables. In these database I keep running accross the same type of queries. they run very slowly and I think there must be away to rewrite these. Can anyone show me a better way? I created the example of the queries and the final query. I will post them all.  query4 in this example is the main query to run.
query1
SELECT Table1.AAA, Table1.BBB, Table1.CCC, Table1.DD, Table1.EE
FROM Table1;

query2
SELECT Table2.AAA, Table2.BBB, Table2.CCC, Table2.FF, Table2.GG
FROM Table2;

query3_union
SELECT Table1.AAA, Table1.BBB, Table1.CCC
FROM Table1
UNION SELECT Table2.AAA, Table2.BBB, Table2.CCC
FROM Table2;

query4
SELECT Query3_Union.AAA, Query3_Union.BBB, Query3_Union.CCC, Query1.DD, Query1.EE, Query2.FF, Query2.GG
FROM (Query3_Union LEFT JOIN Query1 ON (Query3_Union.AAA = Query1.AAA) AND (Query3_Union.BBB = Query1.BBB) AND (Query3_Union.CCC = Query1.CCC)) LEFT JOIN Query2 ON (Query3_Union.AAA = Query2.AAA) AND (Query3_Union.BBB = Query2.BBB) AND (Query3_Union.CCC = Query2.CCC);

Open in new window

0
Comment
Question by:Keking
[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
3 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 250 total points
ID: 35085315
create nonclustered indexes on table1 and table2 on AAA, BBB, CCC and include DD/EE or FF/GG as secondary columns

the statement would look like this:

create nonclustered index ix_Table1 on table1 (AAA, BBB, CCC) include (DD, EE)
create nonclustered index ix_Table2 on table1 (AAA, BBB, CCC) include (FF, GG)
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35085383
Can you clearly define "they run very slowly" in chronological terms please?

Is this slowness the total time to run all the queries?, or just one?

There are many things that will contribute to "Slowness:
Do you have your indexes optimized?
How many records are you dealing with?
What is the network Architecture?
How are you running the queries?
...etc
0
 
LVL 50

Assisted Solution

by:Lowfatspread
Lowfatspread earned 250 total points
ID: 35086910
look at indexes but ...  (can't use include until sql 2005...)

wouldn't a pass thru query of

select coalesce(a.aaa,b.aaa) as aaa
       ,coalesce(a.bbb,b.bbb) as bbb
 ,coalesce(a.ccc,b.ccc) as ccc
,a.dd.a.ee.b.ff.b.gg
from table1 as a
full outer join table2 as b
on a.aaa=b.aaa
and a.bbb=b.bbb
and a.ccc-b.ccc
order by 1,2,3

be a better solution?

ie let sql server do all the IO/retrieval...
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

734 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