Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4991

Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4993

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php:4991) in /www/htdocs/v030397/mysql-qotd/wp-includes/feed-rss2-comments.php on line 8
Comments on: Question 43: Which indexes would you create to speed up the query below? http://mysql-qotd.casperia.net/archives/317 mysql 5.0/5.1 questions for learning purposes Fri, 06 Aug 2010 16:56:36 +0000 http://wordpress.org/?v=abc hourly 1 By: plogi http://mysql-qotd.casperia.net/archives/317/comment-page-1#comment-49 plogi Tue, 18 May 2010 15:37:11 +0000 http://mysql-qotd.casperia.net/?p=317#comment-49 <b> a c The index on jdate will restrict the rows from j1tst and the index on j2tst.jttype will support the join. Group by with columns from both tables can prevent the use of indexes and change the plan. Try explaining the query below: <pre>select jdate,jtname,sum(jtsum) from j1tst v1 inner join j2tst v2 on (v1.jttype=v2.jttype) where jdate between '2010-01-01' and '2010-01-10' group by jdate,jtname;</pre> </b>
a c

The index on jdate will restrict the rows from j1tst and the index on j2tst.jttype will support the join.
Group by with columns from both tables can prevent the use of indexes and change the plan.
Try explaining the query below:

select jdate,jtname,sum(jtsum) from j1tst v1
  inner join j2tst v2 on (v1.jttype=v2.jttype)
  where jdate between '2010-01-01' and '2010-01-10'
  group by jdate,jtname;

]]>