List:General Discussion« Previous MessageNext Message »
From:Rick James Date:November 16 2012 8:13pm
Subject:RE: Query Optimization
View as plain text  
It depends on the distribution of the 4 'values' in that field.
If the cardinality is poor, then INDEX(VAL) won't be used, and they will all do a table
scan.

> -----Original Message-----
> From: Anupam Karmarkar [mailto:sb_akarmarkar@stripped]
> Sent: Friday, November 16, 2012 12:36 AM
> To: mysql@stripped
> Subject: Query Optimization
> 
> Hi All,
> 
> Consider a scenario, I have table XYZ which contains value follow BLUE RED
> GREEN NULL
> 
> following are queries we can use get this values
> 
> 1. SELECT * FROM XYX WHERE VAL IN ('BLUE','RED','GREEN'); 2. SELECT * FROM
> XYZ WHERE VAL IS NOT NULL 3. SELECT * FROM XYZ WHERE VAL = 'BLUE' OR
> VAL='RED' OR VAL='GREEN'
> and more
> 
> So which one is good in terms of optimization. I guess, 1 and 3 are similar
> in term of formation.
> 
> 
> --Anupam
Thread
Query OptimizationAnupam Karmarkar16 Nov
  • Re: Query OptimizationBenaya Paul16 Nov
  • RE: Query OptimizationRick James16 Nov