Slow Running simple SQL Script...

I have a simple SQL Script that is running against EMPTY tables that are NOT INDEXED. Again no data is in these tables are present. The query takes about 18 seconds to process and return BLANK results. We need it to be processed in 2-3 seconds.

QUESTION: Does the fact that the 4 tables involved are not INDEXED have any bearing on how quickly the query is returning blank results....?

LVL 17
MIKESoftware Solutions ConsultantAsked:
Who is Participating?
MIKEConnect With a Mentor Software Solutions ConsultantAuthor Commented:
Update,... it was just explained to me that the "tables" involved are actually,... VIEWS... so any additional comments are appreciated, but I'm going to start looking at each view to see if any issues.
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
If there is no data in the tables then it should have no bearing if things are indexed or not.
MIKESoftware Solutions ConsultantAuthor Commented:
When I query certain columns, say "SELECT T1.Col1, T2.Col2, T3.Col3" from the various VIEWS ..the query processes in 18 seconds.

When I do "SELECT *" on these same VIEWS, processes in 2 seconds...

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

Surendra NathConnect With a Mentor Technology LeadCommented:
first... do update your statistics

Run the below stored procedure


Open in new window

then execute the query again... this happens when the table used to contain a lot of data earlier and now it was truncated and the statics are stale.
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
Views - do they have any WHERE clause (or other filter) in them?
Anthony PerkinsConnect With a Mentor Commented:
So the Views do not return any data, what about the underlying tables how many rows do they contain?
Kusala WijayasenaConnect With a Mentor Software EngineerCommented:
Could you please paste you SQL Script here ?
jogosConnect With a Mentor Commented:
You can have a very complex view that calls different functions but returns nothing because of the filtering done by the join, where or having-clause. (as others indicate before)

Look at the execution plan of your query that will give you an indication  where that time is going.
Maybe the indexes on the underlying tables are not good in combination with the filtering/joins and you need to dig trough the whole table.

Need for updated statistics and index maintenance are also a possibility but only after you have seen where your time is lost.  Always see first, change 1 thing, look again, .... if not you can change  10 things and don't know what did do the trick.
MIKESoftware Solutions ConsultantAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.