We help IT Professionals succeed at work.

query optimization

MD SHAMIM
MD SHAMIM asked
on
106 Views
Last Modified: 2018-01-17
how could i improve below query performance .in test server it takes more than 2 minutes .In prod busy server( millions of rows ) it will take more time to execute .any good thoghts would help .

DECLARE @Date varchar(10) = '3/16/2017';
DECLARE @Client varchar(50) = 'logix';
SELECT count(*) AS 'SSN Checks'
FROM vwEvent
WHERE EventType = 'SigningPing'
AND EventDate = @Date
AND EventParam4 = @Client
AND EventParam2 like '%/NameSSN/%'


thanks all in advance
Comment
Watch Question

Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
For starters, post the T-SQL for view vwEvent into this question

>DECLARE @Date varchar(10) = '3/16/2017';
Bad developer.  Very bad.  Why are we storing dates as a varchar?   This at minimum forces implicit conversion which adds to query processing time.

>AND EventParam2 like '%/NameSSN/%'
Lose the LIKE comparison if possible, as these by definition are slow.

Author

Commented:
thank you .could you please make a change to the query .what should i use for date instead of varchar ? are you suggesting something like

AND EventParam2 like 'NameSSN/%' ?
Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
>what should i use for date instead of varchar ?
Use date.  This assumes that the EventDate column in your view is a date data type.

>are you suggesting something like .. AND EventParam2 like 'NameSSN/%' ?
I'm suggesting not using LIKE and a wildcard % of any kind if that is possible.

Author

Commented:
do you think below query is better than original .and any other suggestion please ?

DECLARE @Date date = '3/16/2017';
DECLARE @Client varchar(50) = 'logix';

SELECT  count(*) AS 'SSN Checks' FROM vwEvent  
WHERE EventType= 'SigningPing'
 AND EventDate = @Date
 AND EventParam4 = @Client
 AND EventParam2 = 'NameSSN'
SQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
after all conversation with JIm Horn got my solution .thank you GURU

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.