
%*********************************************************************************************************************************
% this relation gives the shape of the input query plan.

parent(planRoot, nodeA).
parent(nodeA, nodeB). 

%*********************************************************************************************************************************
% the three relations join, selection, and tableScan describe the various nodes in the query plan.  The first att
% in each relation is the name of the node in the query plan.  The second att in the join and selection nodes lists
% all of the boolean predicates that are ANDed together in the node.  The second att in the tableScan relation
% lists all of the attributes that will be pulled upwards from the table scan. 

selection(nodeA, [pred1]).
tableScan(nodeB, [table1(att1), table1(att2)]). 

%*********************************************************************************************************************************
% the stats relation gives, for each node, the number of distinct attribute values coming out of the node (the second attribute),
% and the number of tuples coming out of the node (the third attribute).  It is assumed that tuples in this relation are defined
% for each of the table scans

stats(nodeB, [numVals(table1(att1), 100), numVals(table1(att2), 500)], 10000).

%*********************************************************************************************************************************
% this lists all of the predicates that appear in anywhere in the underlying query.  The assumption is that the query 
% has a WHERE clause of the form pred1 AND pred2 AND so on. The boolPred relation has two attributes.  The first att 
% is an ID for the boolPred, the second att is a list of database attributes that appear in the boolPred. 

boolPred(pred1, [table1(att1), table1(att2)]).

%*********************************************************************************************************************************
% there are also three other relations that store the actual expression trees for the predicates: equals, booland, boolor.  

equals(intRes1_1, table1(att1), literal).
equals(intRes1_2, table1(att2), literal).
boolor(pred1, intRes1_1, intRes1_2).
