Applying equality constraints

The following process creates equality constraints. The idea is to detect additional constraints, join options, and filters. Let's take a deep breath and take a look at the following query: if aid = cid and aid = bid, we know that bid = cid. If cid = 4 and all the others are equal, we know that aid and bid have to be 4 as well, which leads us to the following query:

SELECT * 
FROM a, b, c
WHERE a.aid = c.cid
AND aid = bid
AND cid = 4
AND bid = cid
AND aid = 4
AND bid = 4

The importance of this optimization cannot be stressed enough. What the planner did here was open the door for two additional indexes that were not clearly visible in the original query.

By being able to use indexes on all three columns, the query is now a lot cheaper.  The optimizer has the option to just retrieve a couple of rows from the index and use whatever join option makes sense.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset