public class QueryGraph extends Object
A undirected, possibly-cyclic, database-agnostic, graph of DBRow nodes connected by bi-directional edges created from known foreign keys and the expressions used in the query.
This class is used to identify cartesian joins by establishing which tables
are included in the join, and which are not. If any node cannot be reached by
traversing the graph, a AccidentalCartesianJoinException may be
thrown during querying.
Ignored foreign keys are not included as edges.
DBRows returned by DBExpression.getTablesInvolved() will be used to
creates edges from expressions in the query.
Support DBvolution at Patreon
| Constructor and Description |
|---|
QueryGraph(List<DBRow> allQueryTables,
List<BooleanExpression> expressions)
Create a graph of the tables and connections for all the DBRows and
BooleanExpressions provided.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAndConnectToRelevant(List<DBRow> otherTables,
List<BooleanExpression> expressions)
Add the provided DBRows/tables and expressions to this QueryGraph,
generating new nodes and edges as required.
|
void |
addAndConnectToRelevant(List<DBRow> otherTables,
List<BooleanExpression> expressions,
boolean requiredTables)
Add the provided DBRows/tables and expressions to this QueryGraph,
generating new nodes and edges as required.
|
void |
addOptionalAndConnectToRelevant(List<DBRow> otherTables,
List<BooleanExpression> expressions)
Add the provided DBRows/tables and expressions to this QueryGraph,
generating new nodes and edges as required.
|
QueryGraph |
clear()
Removes all state and prepares the graph for re-initialization.
|
edu.uci.ics.jung.graph.Graph<QueryGraphNode,DBExpression> |
getJungGraph()
Create a Jung graph of this QueryGraph for display purposes.
|
List<DBRow> |
toList()
Return tables in the QueryGraph as a list.
|
List<DBRow> |
toListIncludingCartesian()
Return all tables in the QueryGraph as a list.
|
List<DBRow> |
toListIncludingCartesianReversable(Boolean reverse)
Return all tables in the QueryGraph as a list.
|
List<DBRow> |
toListReversable(boolean reversed)
Return tables in the QueryGraph as a list.
|
boolean |
willCreateCartesianJoin()
Scans the QueryGraph to detect disconnected DBRows/tables and returns TRUE
if a disconnection exists.
|
boolean |
willCreateFullOuterJoin()
Scans the QueryGraph to detect full outer join.
|
public QueryGraph(List<DBRow> allQueryTables, List<BooleanExpression> expressions)
allQueryTables - expressions - public QueryGraph clear()
Support DBvolution at Patreon
public final void addAndConnectToRelevant(List<DBRow> otherTables, List<BooleanExpression> expressions)
otherTables - expressions - public final void addOptionalAndConnectToRelevant(List<DBRow> otherTables, List<BooleanExpression> expressions)
The DBrows/tables will be added as optional (that is "outer join" tables) and displayed as such.
otherTables - expressions - public final void addAndConnectToRelevant(List<DBRow> otherTables, List<BooleanExpression> expressions, boolean requiredTables)
The DBrows/tables will be added as optional (that is "outer join" tables) if requiredTables is FALSE.
otherTables - expressions - requiredTables - public boolean willCreateCartesianJoin()
Support DBvolution at Patreon
public boolean willCreateFullOuterJoin()
Support DBvolution at Patreon
public List<DBRow> toList()
Starting from a semi-random table (see getStartTable()) traverse
the graph and add all nodes found to the list.
This method does not check for discontinuities. If there is a cartesian
join/discontinuity present only some of the nodes will be returned. Use toListIncludingCartesian() if you need to span a discontinuity.
Some optimization is attempted, by trying to include all the required/inner tables first before adding the optional/outer tables. This avoids a common problem of a query that spans the intersection of 2 optional/outer tables, creating mid-query cartesian join that could have been avoided by including a related required/inner table first.
Support DBvolution at Patreon
public List<DBRow> toListReversable(boolean reversed)
Starting from a semi-random table (see getStartTable()) traverse
the graph and add all nodes found to the list.
This method does not check for discontinuities. If there is a cartesian
join/discontinuity present only some of the nodes will be returned. Use toListIncludingCartesian() if you need to span a discontinuity.
Some optimization is attempted, by trying to include all the required/inner tables first before adding the optional/outer tables. This avoids a common problem of a query that spans the intersection of 2 optional/outer tables, creating mid-query cartesian join that could have been avoided by including a related required/inner table first.
reversed - TRUE if the list should be reversed, FALSE otherwise
Support DBvolution at Patreon
public List<DBRow> toListIncludingCartesian()
Starting from a semi-random table (see getStartTable()) traverse
the graph and add all nodes found to the list.
This method scans across discontinuities. If there is a cartesian
join/discontinuity present all of the nodes will be returned. Use toList() if you need to avoid spanning a discontinuity.
Some optimization is attempted, by trying to include all the required/inner tables first before adding the optional/outer tables. This avoids a common problem of a query that spans the intersection of 2 optional/outer tables, creating mid-query cartesian join that could have been avoided by including a related required/inner table first.
Support DBvolution at Patreon
public List<DBRow> toListIncludingCartesianReversable(Boolean reverse)
Starting from a semi-random table (see getStartTable()) traverse
the graph and add all nodes found to the list.
This method scans across discontinuities. If there is a cartesian
join/discontinuity present all of the nodes will be returned. Use toList() if you need to avoid spanning a discontinuity.
Some optimization is attempted, by trying to include all the required/inner tables first before adding the optional/outer tables. This avoids a common problem of a query that spans the intersection of 2 optional/outer tables, creating mid-query cartesian join that could have been avoided by including a related required/inner table first.
reverse - TRUE if the list needs to be reversed, FALSE otherwise
Support DBvolution at Patreon
public edu.uci.ics.jung.graph.Graph<QueryGraphNode,DBExpression> getJungGraph()
Other graphs are available but we use Graph.
Support DBvolution at Patreon
Copyright © 2018. All Rights Reserved.