Closed d11wtq closed 12 years ago
I think you're right. Right now I only allow join between two relations where some of the attributes overlap. It raise an exception when none of the attributes overlap (product) and when all of the attributes overlap (intersection).
Granted, using the proper operation will be more efficient, I should probably just allow join to be used in all 3 cases and then let the optimizer select the most appropriate one given the headers from both relations.
To fix this I'm going to see about removing the validations, and then see if the algorithm I used for join is general purpose enough to handle all 3 cases. I can't recall if I optimized it for the one case it handles or not. Either way it should be relatively simple to change if need be.
Also, I should note, one of the advantages to using join for all 3 cases is that as the schemas change, assuming same-named attributes refer to the same thing, the operation should "just work". Compare this with other approaches, like those used in SQL, if you add columns to both tables every query needs to be changed.
BTW Veritas::TABLE_DEE
and Veritas::TABLE_DUM
are defined as constants.
Absolutely, it would be simpler and more correct. The requirement for the unique key ensures the "expected" thing is done for most cases. I think only once in my career have I ever needed a true natural (cross) join without any key-joining and I can't really recall what it was (it was for some one-off data crunching we were doing). Either way, making the engine do the academically defined thing is definitely better than not :P
Thanks for the tip on the constants. I assumed there would be constants somewhere, but was just doing it the long-way around for learning purposes :)
@d11wtq btw, this has been resolved in https://github.com/dkubb/veritas/commit/e8c77ba130e4c92d02707fd1bb6fe6488ae4579e
Problem One (possibly the only issue here is unnecessary validation?).
Joining relations with no common attributes doesn't work due to an assertion in Veritas:
From page 88 of Database in Depth:
(snip)
Problem two (possibly solved simply by fixing the first issue):
TABLE_DEE joined with any relation, r should always yield the relation r.
From page 89 (pre-amble about a prefix notation for Tutorial D's JOIN):
(snip)
(snip)
Let me know if I've got the wrong end of the stick or if this is indeed a bug :) I'm off to bed!