Query factory goal is to build a tree of filters that should allow calculating results of a given SQL query. As there are always several possible trees for the same result, the query factory should first start a cost calculation in order to estimate number of I/O calls to calculate query according to the chosen tree and then move filters to a different position and start calculation again on the updated tree.
The query factory should then repeat updating the filter tree, moving filters to a different position, and run cost calculation again according to the new tree, using the lowest found cost as budget limit, in order to find tree construct that will give the fastest query. Typical move operation include: move filter trees before or after join operation, change sequence order of the join operations, change sequence order of a chain of filters or replace select by filtering filter.
Once cost has been estimated, and fastest way to calculate results has been determinate, the query factory should then start actual execution of the request, collect and broadcast results.
Wiki: Cost_calculation
Wiki: Query_execution
Wiki: Set_engine
Wiki: Specification