In this part we are going to analyze a bit more complex query
than before.
This query is a 6-way join.
The query is:
SELECT
supp_nation,
cust_nation,
l_year,
SUM(volume) AS revenue
FROM
(
SELECT
n1.n_name AS supp_nation,
n2.n_name AS cust_nation,
extract(year FROM l_shipdate) as
l_year,
l_extendedprice * (1 - l_discount) AS …
In the previous part we showed how NDB will parallelise a
simple
2-way join query from TPC-H. In this part we will describe
how
the pushdown of joins to a storage engine works in the MySQL
Server.
First a quick introduction to how a SQL engine handles a
query.
The query normally goes through 5 different phases:
1) Receive query on the client connection
2) Query parsing
3) Query optimisation
4) Query execution
5) Send result of query on client connection
The result of 1) is a text string that contains the SQL query
to
execute. In this simplistic view of the SQL engine we will
ignore
any such things as prepared statements and other things making
the
model more complex.
The text string is parsed by 2) into a data structure that
represents
the query in objects that match concepts in the SQL engine.
Query …
If you use the EXPLAIN SELECT statement to see how your
subqueries are treated by MySQL, you may sometimes meet the
"unique_subquery" optimization. Here is how the manual describes it:
"unique_subquery: this type replaces ref for some
IN subqueries of the following form: value IN (SELECT
primary_key FROM single_table WHERE some_expr);
unique_subquery is just an index lookup function that replaces
the subquery completely for better efficiency".Few weeks ago,
while I was reviewing a patch fixing a bug in unique_subquery, I got a
"simplification" pulsion. I told myself that:
- unique_subquery is an optimization for a special case of simple subqueries (single inner …