Prev | Current Page 258 | Next

Brad Ediger

"Advanced Rails"

35 sec)
Rather than defining the steps the database engine takes to fulfill the query, this syntax
shows the tables that contribute to the query. As this is a simple inner join, the
two tables that comprise the FROM clause are listed, and the select_type of both is
SIMPLE (which indicates that they are not components of a union or subquery).
The WHERE clause restricts the first table to one row, referenced by the primary key.
The type of that lookup is const, which is the fastest type. The possible_keys column
shows the possible indexes that could satisfy the query (PRIMARY), and the key
column shows the one that the query planner chose.
The second table, indexed by foreign key, uses a ref lookup on the index, which is
fast enough in this case as the number of rows returned (40) is small. If we had not
defined the idx_listing_id index, the type would be ALL rather than ref, indicating
that the entire table must be scanned.
A basic understanding of your database??™s query planner is vital to writing good queries
and tracking down bad ones. Even for PostgreSQL and MySQL, freely available
open source databases, the documentation is very readable and of excellent quality.
Architectural Scalability
One of the hardest parts of building and deploying a web application is growing it.
Luckily, Rails was designed with scalability in mind. The Rails scalability mantra is
shared-nothing??”the idea that each application server should stand on its own, not
having to coordinate with other application servers to handle a request.


Pages:
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270