On Jun 2, 12:38*am, Fin <tdavi... (AT) hotmail (DOT) com> wrote:
Quote:
In the article, sure there is no join to PRODUCT_DIM after defining
the FK, but neither did he select any specific columns/records from
said table. It was only much later that I realized presumably it only
ensures record integrity. I was hoping it would serve a dual purpose
and allow me to 'fetch' the column DESC_SYM by the same method.
I know this is very long winded for little or no benefit but it would
help me enormously if someone could confirm or explain it better ? |
You have reached the correct conclusion.
It is quite common to include a join in a query as a form of data
validation - i.e. you only want to see sales results from valid
stores, so you join the sales table with the store table. If there is
a row in the fact table that has an invalid store_id, you don't want
that data.
Foreign keys exist to prevent this situation.
However, foreign keys do introduce some overhead, and if the
application(s) that insert data into the tables do their own
validation it's not necessary to force the database to do additional
validation.
The article is pointing out that foreign keys provide the optimizer
with additional information that can allow the optimizer to eliminate
these lossless joins. Furthermore, because DB2 allows you to have a
"NOT ENFORCED" foreign key constraint you can eliminate the
traditional overhead associated with foreign keys.
In the article the join with the DATE_DIM table can't be avoided with
a foreign key because of the local predicate (DATE_DIM.MONTH = ?).
In your case, because you are fetching a column from the joined table
(DESC_SYM) you can't eliminate the join.