![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm looking for a loose algorithm, not code but is there a way in a query building scenario to determine if relationships in a SQL FROM clause are in conflict without actually executing the SQL? For example, 3 tables may be joined in a triangle and changing the direction of one join may invalidate the other relationships. Many commercial query builing interfaces seem to accomplish this (like MS SQL Server) although I don't need all the extra functionality they provide (like automatic conflict corrections etc...). Thx... |
#3
| |||
| |||
|
#4
| |||
| |||
|
#5
| |||
| |||
|
|
I mean changing a left outer join into a right outer join... or I mean, in the course of creating a query, the user adds a join of a type that conflicts with the joins that are already configured. E.g. Assuming a query exists like this.... SELECT TableA.* FROM TableB INNER JOIN TableA ON TableB.id1 = TableA.id1 INNER JOIN TableC ON TableB.id3 = TableC.id3 AND TableA.id3 = TableC.id3 ..which is just 3 tables inner joined in a triangle. If the user then tries to change the relationship between A and B to make sure all records of A appear in the result, then the query builder software needs to somehow report a conflict in the relationships because the relationship between A and C must change as well. I hope I explained that properly... -- Posted via http://dbforums.com |
#6
| |||
| |||
|
|
The software would need human intelligence. Maybe the single "reversal" is what is needed to be done to get the "correct/desired" results. How would the software be able to interpret the semantics of the data/query? |
#7
| |||
| |||
|
|
..and just to confuse you further, my thoughts were that some recursive function would be needed to traverse all existing relationships with the participating tables of any newly proposed relationship. And the purpose of that would be to verify that the newly proposed relationship would coexist with existing ones without conflict. I've been told this may involve heavy network modeling algorithms (that would be beyond my understanding - entirely possible) and the best course of action may be to let the user's query fail and put the responsibility on them. But I'm not ready to give up on this yet. So any assistance would be appreciated....Thx |
#8
| |||
| |||
|
| It's not very simple, but also not very complicated. Just think of the join as a graph: nodes are the relations, edges are join conditions. You start from the node/relation that has to be fully in the result. If there is a simple path (no cycles) that starts in this node and ends with the edge (R1,R2) then the join between R1 and R2 should be an outer join on the side of R1. -- Jan Hidders |
I was thinking
#9
| |||
| |||
|
#10
| ||||
| ||||
|
|
Originally posted by Jan Hidders It's not very simple, but also not very complicated. Just think of the join as a graph: nodes are the relations, edges are join conditions. You start from the node/relation that has to be fully in the result. If there is a simple path (no cycles) that starts in this node and ends with the edge (R1,R2) then the join between R1 and R2 should be an outer join on the side of R1. Awesome. I'm just on the verge of comprehending I was thinkingnodes are tables but no, they're relations. That makes more sense. |
|
So in my above example I'd have 3 nodes...A is related to B, B is related to C, and C is related to A and 3 edges. That would be a cycle (#edges > (#nodes-1)), is that right? |
|
I assume verifying a cycle would be harder than verfying the simple path you describe above. Do you know of any documentation that describes this further? Thanks again! |
|
..or are you saying only cycles have potential for conflict and my software should evaluate the simple path leading up to the last edge - then if the last edge works as you describe then no conflict? |
![]() |
| Thread Tools | |
| Display Modes | |
| |