Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am stuck up with Database Query Performance once again..

One Select Query - is taking a lot of time to execute - 7minutes for 30records.

What I have tried:

SQL
select distinct incoming.IC_NO,
(case when ISNUMERIC(incoming.IC_RECEIVERS_SR_ID) <> 1 then incoming.IC_RECEIVERS_SR_ID when ISNUMERIC(incoming.IC_RECEIVERS_SR_ID) = 1
then (select sr.SR_NAME from SENDERRECEIVER sr where sr.SR_ID = cast( incoming.IC_RECEIVERS_SR_ID as numeric) )end) as 'IC_RECEIVERS_SR_ID',
(select courier.CSP_NAME from COURIERSERVICEPROVIDER courier where courier.CSP_ID = incoming.IC_CSP_ID) as 'Courier Service Name',
equip.EQ_DESC as 'Site',
(select REPLACE(t.EQ_DESC,'–','') from EQUIPMENT t where t.EQ_L1 = equip.eq_code and t.EQ_LEVEL = 2 and incoming.IC_SUBHUBLOC = t.EQ_CODE) as 'Subhurb',
incoming.IC_WEIGHT, incoming.IC_RATE , incoming.IC_CONSIGNMENTRECDATETIME,
incoming.IC_ReceiverCity as 'Receiver City',
incoming.IC_RECEIVERPINCODE as 'Receiver Pincode',
incoming.IC_AIRWAYBILLNO as 'Airway Bill No',
incoming.IC_AMOUNT as 'Amount', incoming.IC_CREATEDBY as 'Created By',
incoming.IC_COURIERTYPE as 'Courier Type'
from INCOMINGCONSIGNMENT incoming , equipment equip,
equipment subhurb where 1=1 and IC_CONSIGNMENTRECDATETIME between '03 Jul 2017' and '03 Jul 2017' 


Please help me...
Posted
Updated 3-Jul-17 23:10pm
Comments
F-ES Sitecore 4-Jul-17 5:11am    
Use JOINs rather than sub-queries to get data from other tables (eg Courier Service Name etc). Beyond that look at the query plan via SQL Management Studio and maybe build indexes on the columns included in "WHERE" queries, however that may have a knock-on effect with insert performance.

Tuning queries is a massive topic on its own, lots of articles out there if you google.

1 solution

wath database ? sql server ? oracle ? anything else ?

if sqlserver, include actual Execution plan and estimated execution plan - if any index missing, sql server will display command to create missing index

case and cast really needed ? should be done in client (c#, vb ...) database is for retrieving data, not for calcing

subquery maybe slower then joining
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900