- Cost-based query optimization allows you to assign costs to operations and assign costs to partial plans, which allows them to find better search plans with lower costs.
- Possible because query plans are simple, they have data statistics and they have meta-data.
- Cost of an operation is proportional to disk accesses. A cost unit equals a random read of data page (4Kb).
- Variable length fields (
BLOB,VARCHAR, etc.) require extra guess work and adds to the cost of that operation. I would assume this means variable length fields would be a bad idea when used in an index. - MySQL does internal optimization on your queries to decide how it should do searches and joins based on the cost of each way to execute the query. Each choice is called a “plan” and each plan has a cost (see above).
- The problem with this approach is that the more joins you add the more plans (options) are added to the mix for optimization, which means that as you add joins the more time the “optimizer” takes to optimize your query. Evidently, this limit is somewhere around 5-7 joins in a single table.
- With 5.0 they’ve introduced a “Greedy search” that lets you suggest the plan, which is a trade off as the optimizer is skipped (at least this is how it sounds from his explanation).
- Users can influence the choice of indexes with the
USE INDEX,FORCE INDEXandIGNORE INDEXsytnax. These should be used with extreme care as indexes can be added and dropped. - You can also check out optimizer_search_depth whith tells the optimizer how much effort to put into looking for the best search plan. The default is automatic.
- Another option is optermizer_prune_level.
- The third way to force optimization on joins is to use the
STRAIGHT_JOINsyntax to force join order. - The range optimizer can detect ranges that can be merged, such as
SELECT * FROM tb1 WHERE foo < 10 OR foo < 20. In doing so it finds the minimal sequence of smallest possible disjoint intervals.
Speeding-up Queries: New Features of the MySQL 5.0 Query Engine (Part 1)
Posted on Wednesday, April 26th, 2006 at 6:52 pm in db, mysql, optimization
Projects
-
SimpleGeo
Ready-to-use location infrastructure for developers.
-
tweetimag.es
Consistent, predictable Twitter avatars backed by an enterpise CDN.
Open Source Projects
Net_Curl php
Net_Gearman php
Payment_Process php
Services_Digg php
Services_Facebook php
Services_Twitter php
Services_oEmbed php
Services_urlTea php
db_virtual php
framework php
jax php
python-oauth2 python
python-simplexml python
services_flickr php
Categories
/dev/random 75
2006 1
2007 1
2008election 2
505 e denny way 2
america 2
american idol 5
apache 1
apple 7
architecture 2
asia 1
back 1
barack obama 1
basketball 1
benchmarks 1
bike 2
biking 4
book reviews 3
burrito 2
bush 1
california 3
cambodia 1
cars 1
carsonified 1
change 1
charity 1
cities 1
clap your hands say yeah 1
cloud computing 1
clustering 5
code 8
coding 4
college 2
conferences 2
correlateus 1
craigslist 1
crocodile 1
database 3
db 10
death 1
debian 1
delicious 1
dieting 2
digg 10
django 1
drugs 1
ec2 1
england 2
enterprise 1
entrepreneurship 1
environment 6
europe 1
exercise 4
facebook 1
food 1
fowa 2
framework 4
fraternity 15
free speech 1
fremont 1
friends 2
funny 4
gambling 1
gdd20007 4
geek related 112
gobama 1
google 4
hacking 1
health 4
health/fitness 8
homecoming 1
html/css 9
i almost care 3
ian mcferon 1
in the news 85
innodb 2
internet 4
iphone 5
iraq 2
javascript 2
jokes 2
jquery 2
kasabian 1
kirkland 1
lamp 1
laos 1
libertarianism 7
lists 1
london 1
man law 1
maya 2
michigan 2
midwest 1
mississippi 1
missy higgins 1
money 1
move to seattle 12
moving 1
music 4
musings 30
mvc 1
my cat 9
mysql 16
mysqlconf 1
mysqli 1
nagios 1
neumos 1
obituary 1
ok go 1
open source 3
operation fat ass 1
optimization 1
parc on summit 5
partitioning 1
pear 19
personal 100
photography 1
php 38
politics 84
portland 1
pownce 1
presenations 1
programming 15
python 3
rants 10
religion 1
replication 2
reviews 11
ruby 1
running 4
san diego 1
scaling 2
seattle 7
site updates 10
slippery slope 1
snowboarding 1
social media 2
social networks 2
social web 1
sports 1
ssl 1
startups 1
stupid schools 1
surgery 1
swimming 3
sxsw 1
system admin 10
talks 2
technology 1
thailand 5
the decemberists 1
theft 1
this interweb thingy 15
travel 19
trek 5200 1
triathlon 3
tv shows 12
twitter 3
Uncategorized 1
vacation 2
vietnam 1
war 2
webdave 1
wheels 1
wikipedia 1
wordpress 1
work 18
year in review 10
youtube 1
zoom 2
zorka 1