13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Getting More Information About Databases<br />

301<br />

Table 12.8<br />

Type<br />

Possible Select Types as Shown in Output from EXPLAIN<br />

Description<br />

SIMPLE<br />

PRIMARY<br />

UNION<br />

DEPENDENT UNION<br />

UNION RESULT<br />

SUBQUERY<br />

DEPENDENT SUBQUERY<br />

DERIVED<br />

UNCACHEABLE SUBQUERY<br />

UNCACHEABLE UNION<br />

Plain old SELECT, as in this example<br />

Outer (first) query where subqueries <strong>and</strong> unions are used<br />

Second or later query in a union<br />

Second or later query in a union, dependent on the primary<br />

query<br />

The result of a UNION<br />

Inner subquery<br />

Inner subquery, dependent on the primary query (that is, a correlated<br />

subquery)<br />

Subquery used in FROM clause<br />

A subquery whose result cannot be cached <strong>and</strong> must be reevaluated<br />

for each row<br />

The second or later select in a UNION that belongs to an<br />

uncacheable subquery<br />

The column table just lists the tables used to answer the query. Each row in the result<br />

gives more information about how that particular table is used in this query. In this case,<br />

you can see that the tables used are orders, order_items, customers, <strong>and</strong> books.(You<br />

know this already by looking at the query.)<br />

The type column explains how the table is being used in joins in the query.The set<br />

of values this column can have is shown in Table 12.9.These values are listed in order<br />

from fastest to slowest in terms of query execution.The table gives you an idea of how<br />

many rows need to be read from each table to execute a query.<br />

Table 12.9<br />

Type<br />

Possible Join Types as Shown in Output from EXPLAIN<br />

Description<br />

const or system<br />

eq_ref<br />

fulltext<br />

ref<br />

ref_or_null<br />

The table is read from only once.This happens when the table has<br />

exactly one row.The type system is used when it is a system table, <strong>and</strong><br />

the type const otherwise.<br />

For every set of rows from the other tables in the join, you read one<br />

row from this table.This type is used when the join uses all the parts of<br />

the index on the table, <strong>and</strong> the index is UNIQUE or is the primary key.<br />

A join has been performed using a fulltext index.<br />

For every set of rows from the other tables in the join, you read a set of<br />

table rows that all match.This type is used when the join cannot choose<br />

a single row based on the join condition—that is, when only part of the<br />

key is used in the join, or if it is not UNIQUE or a primary key.<br />

This is like a ref query, but <strong>MySQL</strong> also looks for rows that are NULL.<br />

(This type is used mostly in subqueries.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!