veritas-optimizer 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. data/Gemfile +33 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +27 -0
  4. data/Rakefile +25 -0
  5. data/TODO +75 -0
  6. data/config/flay.yml +3 -0
  7. data/config/flog.yml +2 -0
  8. data/config/roodi.yml +16 -0
  9. data/config/site.reek +91 -0
  10. data/config/yardstick.yml +2 -0
  11. data/lib/veritas/optimizer/algebra/difference.rb +66 -0
  12. data/lib/veritas/optimizer/algebra/extension.rb +42 -0
  13. data/lib/veritas/optimizer/algebra/intersection.rb +66 -0
  14. data/lib/veritas/optimizer/algebra/join.rb +44 -0
  15. data/lib/veritas/optimizer/algebra/product.rb +70 -0
  16. data/lib/veritas/optimizer/algebra/projection.rb +174 -0
  17. data/lib/veritas/optimizer/algebra/rename.rb +396 -0
  18. data/lib/veritas/optimizer/algebra/restriction.rb +259 -0
  19. data/lib/veritas/optimizer/algebra/summarization.rb +42 -0
  20. data/lib/veritas/optimizer/algebra/union.rb +66 -0
  21. data/lib/veritas/optimizer/logic/connective/binary.rb +254 -0
  22. data/lib/veritas/optimizer/logic/connective/conjunction.rb +122 -0
  23. data/lib/veritas/optimizer/logic/connective/disjunction.rb +122 -0
  24. data/lib/veritas/optimizer/logic/connective/negation.rb +71 -0
  25. data/lib/veritas/optimizer/logic/predicate/comparable.rb +134 -0
  26. data/lib/veritas/optimizer/logic/predicate/enumerable.rb +141 -0
  27. data/lib/veritas/optimizer/logic/predicate/equality.rb +44 -0
  28. data/lib/veritas/optimizer/logic/predicate/exclusion.rb +53 -0
  29. data/lib/veritas/optimizer/logic/predicate/greater_than.rb +54 -0
  30. data/lib/veritas/optimizer/logic/predicate/greater_than_or_equal_to.rb +56 -0
  31. data/lib/veritas/optimizer/logic/predicate/inclusion.rb +53 -0
  32. data/lib/veritas/optimizer/logic/predicate/inequality.rb +44 -0
  33. data/lib/veritas/optimizer/logic/predicate/less_than.rb +54 -0
  34. data/lib/veritas/optimizer/logic/predicate/less_than_or_equal_to.rb +56 -0
  35. data/lib/veritas/optimizer/logic/predicate/match.rb +19 -0
  36. data/lib/veritas/optimizer/logic/predicate/no_match.rb +19 -0
  37. data/lib/veritas/optimizer/logic/predicate.rb +177 -0
  38. data/lib/veritas/optimizer/optimizable.rb +59 -0
  39. data/lib/veritas/optimizer/relation/materialized.rb +40 -0
  40. data/lib/veritas/optimizer/relation/operation/binary.rb +168 -0
  41. data/lib/veritas/optimizer/relation/operation/combination.rb +33 -0
  42. data/lib/veritas/optimizer/relation/operation/limit.rb +149 -0
  43. data/lib/veritas/optimizer/relation/operation/offset.rb +114 -0
  44. data/lib/veritas/optimizer/relation/operation/order.rb +96 -0
  45. data/lib/veritas/optimizer/relation/operation/reverse.rb +94 -0
  46. data/lib/veritas/optimizer/relation/operation/unary.rb +88 -0
  47. data/lib/veritas/optimizer/version.rb +7 -0
  48. data/lib/veritas/optimizer.rb +136 -0
  49. data/lib/veritas-optimizer.rb +3 -0
  50. data/spec/integration/veritas/algebra/difference/optimize_spec.rb +152 -0
  51. data/spec/integration/veritas/algebra/intersection/optimize_spec.rb +152 -0
  52. data/spec/integration/veritas/algebra/join/optimize_spec.rb +110 -0
  53. data/spec/integration/veritas/algebra/product/optimize_spec.rb +176 -0
  54. data/spec/integration/veritas/algebra/projection/optimize_spec.rb +237 -0
  55. data/spec/integration/veritas/algebra/rename/optimize_spec.rb +440 -0
  56. data/spec/integration/veritas/algebra/restriction/optimize_spec.rb +216 -0
  57. data/spec/integration/veritas/algebra/union/optimize_spec.rb +192 -0
  58. data/spec/integration/veritas/logic/connective/conjunction/optimize_spec.rb +234 -0
  59. data/spec/integration/veritas/logic/connective/disjunction/optimize_spec.rb +235 -0
  60. data/spec/integration/veritas/logic/connective/negation/optimize_spec.rb +41 -0
  61. data/spec/integration/veritas/logic/expression/optimize_spec.rb +42 -0
  62. data/spec/integration/veritas/logic/predicate/equality/optimize_spec.rb +90 -0
  63. data/spec/integration/veritas/logic/predicate/exclusion/optimize_spec.rb +131 -0
  64. data/spec/integration/veritas/logic/predicate/greater_than/optimize_spec.rb +100 -0
  65. data/spec/integration/veritas/logic/predicate/greater_than_or_equal_to/optimize_spec.rb +100 -0
  66. data/spec/integration/veritas/logic/predicate/inclusion/optimize_spec.rb +131 -0
  67. data/spec/integration/veritas/logic/predicate/inequality/optimize_spec.rb +90 -0
  68. data/spec/integration/veritas/logic/predicate/less_than/optimize_spec.rb +100 -0
  69. data/spec/integration/veritas/logic/predicate/less_than_or_equal_to/optimize_spec.rb +100 -0
  70. data/spec/integration/veritas/relation/empty/optimize_spec.rb +11 -0
  71. data/spec/integration/veritas/relation/materialized/optimize_spec.rb +37 -0
  72. data/spec/integration/veritas/relation/operation/limit/optimize_spec.rb +140 -0
  73. data/spec/integration/veritas/relation/operation/offset/optimize_spec.rb +98 -0
  74. data/spec/integration/veritas/relation/operation/order/optimize_spec.rb +103 -0
  75. data/spec/integration/veritas/relation/operation/reverse/optimize_spec.rb +113 -0
  76. data/spec/integration/veritas/relation/optimize_spec.rb +33 -0
  77. data/spec/rcov.opts +6 -0
  78. data/spec/shared/idempotent_method_behavior.rb +5 -0
  79. data/spec/shared/logic_connective_binary_optimize_behavior.rb +100 -0
  80. data/spec/shared/optimize_method_behavior.rb +14 -0
  81. data/spec/spec.opts +3 -0
  82. data/spec/spec_helper.rb +16 -0
  83. data/spec/support/add_method_missing.rb +13 -0
  84. data/spec/unit/veritas/optimizer/algebra/difference/empty_left/optimize_spec.rb +17 -0
  85. data/spec/unit/veritas/optimizer/algebra/difference/empty_right/optimize_spec.rb +17 -0
  86. data/spec/unit/veritas/optimizer/algebra/difference/equal_operands/optimize_spec.rb +19 -0
  87. data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimizable_spec.rb +27 -0
  88. data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimize_spec.rb +25 -0
  89. data/spec/unit/veritas/optimizer/algebra/intersection/empty_left/optimize_spec.rb +17 -0
  90. data/spec/unit/veritas/optimizer/algebra/intersection/empty_right/optimize_spec.rb +17 -0
  91. data/spec/unit/veritas/optimizer/algebra/intersection/equal_operands/optimize_spec.rb +17 -0
  92. data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimizable_spec.rb +27 -0
  93. data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimize_spec.rb +21 -0
  94. data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimizable_spec.rb +25 -0
  95. data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimize_spec.rb +16 -0
  96. data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimizable_spec.rb +25 -0
  97. data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimize_spec.rb +16 -0
  98. data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimizable_spec.rb +25 -0
  99. data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimize_spec.rb +18 -0
  100. data/spec/unit/veritas/optimizer/algebra/projection/header_spec.rb +16 -0
  101. data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimizable_spec.rb +26 -0
  102. data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimize_spec.rb +20 -0
  103. data/spec/unit/veritas/optimizer/algebra/projection/set_operand/optimizable_spec.rb +27 -0
  104. data/spec/unit/veritas/optimizer/algebra/projection/set_operand/optimize_spec.rb +23 -0
  105. data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimizable_spec.rb +26 -0
  106. data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimize_spec.rb +16 -0
  107. data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimizable_spec.rb +26 -0
  108. data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimize_spec.rb +20 -0
  109. data/spec/unit/veritas/optimizer/algebra/rename/aliases_spec.rb +31 -0
  110. data/spec/unit/veritas/optimizer/algebra/rename/class_methods/union_aliases_spec.rb +27 -0
  111. data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimizable_spec.rb +25 -0
  112. data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimize_spec.rb +17 -0
  113. data/spec/unit/veritas/optimizer/algebra/rename/header_spec.rb +19 -0
  114. data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimizable_spec.rb +26 -0
  115. data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimize_spec.rb +21 -0
  116. data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimizable_spec.rb +26 -0
  117. data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimize_spec.rb +21 -0
  118. data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimizable_spec.rb +26 -0
  119. data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimize_spec.rb +20 -0
  120. data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimizable_spec.rb +26 -0
  121. data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimize_spec.rb +20 -0
  122. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimizable_spec.rb +28 -0
  123. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimize_spec.rb +20 -0
  124. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimizable_spec.rb +35 -0
  125. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimize_spec.rb +16 -0
  126. data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimizable_spec.rb +27 -0
  127. data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimize_spec.rb +21 -0
  128. data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimizable_spec.rb +25 -0
  129. data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimize_spec.rb +21 -0
  130. data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimizable_spec.rb +27 -0
  131. data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimize_spec.rb +21 -0
  132. data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimizable_spec.rb +26 -0
  133. data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimize_spec.rb +16 -0
  134. data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimizable_spec.rb +42 -0
  135. data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimize_spec.rb +21 -0
  136. data/spec/unit/veritas/optimizer/algebra/restriction/class_methods/optimize_predicate_spec.rb +31 -0
  137. data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimizable_spec.rb +26 -0
  138. data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimize_spec.rb +19 -0
  139. data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimizable_spec.rb +26 -0
  140. data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimize_spec.rb +18 -0
  141. data/spec/unit/veritas/optimizer/algebra/restriction/predicate_spec.rb +16 -0
  142. data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimizable_spec.rb +28 -0
  143. data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimize_spec.rb +22 -0
  144. data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimizable_spec.rb +26 -0
  145. data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimize_spec.rb +18 -0
  146. data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimizable_spec.rb +28 -0
  147. data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimize_spec.rb +22 -0
  148. data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimizable_spec.rb +25 -0
  149. data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimize_spec.rb +17 -0
  150. data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimizable_spec.rb +42 -0
  151. data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimize_spec.rb +22 -0
  152. data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimizable_spec.rb +27 -0
  153. data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimize_spec.rb +27 -0
  154. data/spec/unit/veritas/optimizer/algebra/union/empty_left/optimize_spec.rb +17 -0
  155. data/spec/unit/veritas/optimizer/algebra/union/empty_right/optimize_spec.rb +17 -0
  156. data/spec/unit/veritas/optimizer/algebra/union/equal_operands/optimize_spec.rb +17 -0
  157. data/spec/unit/veritas/optimizer/class_methods/chain_spec.rb +54 -0
  158. data/spec/unit/veritas/optimizer/logic/connective/binary/equal_operands/optimizable_spec.rb +27 -0
  159. data/spec/unit/veritas/optimizer/logic/connective/binary/equal_operands/optimize_spec.rb +17 -0
  160. data/spec/unit/veritas/optimizer/logic/connective/binary/left_spec.rb +14 -0
  161. data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimizable_spec.rb +26 -0
  162. data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimize_spec.rb +21 -0
  163. data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimizable_spec.rb +26 -0
  164. data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimize_spec.rb +21 -0
  165. data/spec/unit/veritas/optimizer/logic/connective/binary/right_spec.rb +14 -0
  166. data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimizable_spec.rb +34 -0
  167. data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimize_spec.rb +21 -0
  168. data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimizable_spec.rb +41 -0
  169. data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimize_spec.rb +17 -0
  170. data/spec/unit/veritas/optimizer/logic/connective/conjunction/left_operand_tautology/optimizable_spec.rb +27 -0
  171. data/spec/unit/veritas/optimizer/logic/connective/conjunction/left_operand_tautology/optimize_spec.rb +17 -0
  172. data/spec/unit/veritas/optimizer/logic/connective/conjunction/optimizable_to_exclusion/optimizable_spec.rb +27 -0
  173. data/spec/unit/veritas/optimizer/logic/connective/conjunction/optimizable_to_exclusion/optimize_spec.rb +36 -0
  174. data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimizable_spec.rb +27 -0
  175. data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimize_spec.rb +17 -0
  176. data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_left_operand/optimizable_spec.rb +27 -0
  177. data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_left_operand/optimize_spec.rb +17 -0
  178. data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_right_operand/optimizable_spec.rb +27 -0
  179. data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_right_operand/optimize_spec.rb +17 -0
  180. data/spec/unit/veritas/optimizer/logic/connective/disjunction/optimizable_to_inclusion/optimizable_spec.rb +27 -0
  181. data/spec/unit/veritas/optimizer/logic/connective/disjunction/optimizable_to_inclusion/optimize_spec.rb +36 -0
  182. data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimizable_spec.rb +41 -0
  183. data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimize_spec.rb +17 -0
  184. data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimizable_spec.rb +26 -0
  185. data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimize_spec.rb +20 -0
  186. data/spec/unit/veritas/optimizer/logic/connective/negation/operand_spec.rb +12 -0
  187. data/spec/unit/veritas/optimizer/logic/predicate/class_methods/optimize_operand_spec.rb +20 -0
  188. data/spec/unit/veritas/optimizer/logic/predicate/comparable/never_comparable/optimizable_spec.rb +58 -0
  189. data/spec/unit/veritas/optimizer/logic/predicate/comparable/never_equivalent/optimizable_spec.rb +58 -0
  190. data/spec/unit/veritas/optimizer/logic/predicate/comparable/normalizable_operands/optimizable_spec.rb +41 -0
  191. data/spec/unit/veritas/optimizer/logic/predicate/comparable/normalizable_operands/optimize_spec.rb +19 -0
  192. data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimizable_spec.rb +29 -0
  193. data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimize_spec.rb +14 -0
  194. data/spec/unit/veritas/optimizer/logic/predicate/contradiction/optimize_spec.rb +16 -0
  195. data/spec/unit/veritas/optimizer/logic/predicate/enumerable/empty_right_operand/optimizable_spec.rb +76 -0
  196. data/spec/unit/veritas/optimizer/logic/predicate/enumerable/one_right_operand/optimizable_spec.rb +76 -0
  197. data/spec/unit/veritas/optimizer/logic/predicate/enumerable/unoptimized_operand/optimizable_spec.rb +49 -0
  198. data/spec/unit/veritas/optimizer/logic/predicate/enumerable/unoptimized_operand/optimize_spec.rb +53 -0
  199. data/spec/unit/veritas/optimizer/logic/predicate/equality/tautology/optimizable_spec.rb +27 -0
  200. data/spec/unit/veritas/optimizer/logic/predicate/exclusion/empty_right_operand/optimize_spec.rb +43 -0
  201. data/spec/unit/veritas/optimizer/logic/predicate/exclusion/one_right_operand/optimize_spec.rb +63 -0
  202. data/spec/unit/veritas/optimizer/logic/predicate/greater_than/contradiction/optimizable_spec.rb +41 -0
  203. data/spec/unit/veritas/optimizer/logic/predicate/greater_than/tautology/optimizable_spec.rb +26 -0
  204. data/spec/unit/veritas/optimizer/logic/predicate/greater_than_or_equal_to/contradiction/optimizable_spec.rb +41 -0
  205. data/spec/unit/veritas/optimizer/logic/predicate/greater_than_or_equal_to/tautology/optimizable_spec.rb +41 -0
  206. data/spec/unit/veritas/optimizer/logic/predicate/inclusion/empty_right_operand/optimize_spec.rb +43 -0
  207. data/spec/unit/veritas/optimizer/logic/predicate/inclusion/one_right_operand/optimize_spec.rb +64 -0
  208. data/spec/unit/veritas/optimizer/logic/predicate/inequality/contradiction/optimizable_spec.rb +27 -0
  209. data/spec/unit/veritas/optimizer/logic/predicate/left_spec.rb +25 -0
  210. data/spec/unit/veritas/optimizer/logic/predicate/less_than/contradiction/optimizable_spec.rb +41 -0
  211. data/spec/unit/veritas/optimizer/logic/predicate/less_than/tautology/optimizable_spec.rb +26 -0
  212. data/spec/unit/veritas/optimizer/logic/predicate/less_than_or_equal_to/contradiction/optimizable_spec.rb +41 -0
  213. data/spec/unit/veritas/optimizer/logic/predicate/less_than_or_equal_to/tautology/optimizable_spec.rb +41 -0
  214. data/spec/unit/veritas/optimizer/logic/predicate/right_spec.rb +25 -0
  215. data/spec/unit/veritas/optimizer/logic/predicate/tautology/optimize_spec.rb +16 -0
  216. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/attribute_spec.rb +19 -0
  217. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/constant_spec.rb +19 -0
  218. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/max_spec.rb +19 -0
  219. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/min_spec.rb +19 -0
  220. data/spec/unit/veritas/optimizer/operation_spec.rb +11 -0
  221. data/spec/unit/veritas/optimizer/optimizable/class_methods/optimizer_spec.rb +32 -0
  222. data/spec/unit/veritas/optimizer/optimizable/optimize_spec.rb +36 -0
  223. data/spec/unit/veritas/optimizer/optimizable_spec.rb +15 -0
  224. data/spec/unit/veritas/optimizer/optimize_spec.rb +15 -0
  225. data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimizable_spec.rb +20 -0
  226. data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimize_spec.rb +17 -0
  227. data/spec/unit/veritas/optimizer/relation/operation/binary/empty_left/optimizable_spec.rb +30 -0
  228. data/spec/unit/veritas/optimizer/relation/operation/binary/empty_right/optimizable_spec.rb +30 -0
  229. data/spec/unit/veritas/optimizer/relation/operation/binary/equal_operands/optimizable_spec.rb +34 -0
  230. data/spec/unit/veritas/optimizer/relation/operation/binary/left_spec.rb +17 -0
  231. data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimizable_spec.rb +35 -0
  232. data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimize_spec.rb +20 -0
  233. data/spec/unit/veritas/optimizer/relation/operation/binary/right_spec.rb +17 -0
  234. data/spec/unit/veritas/optimizer/relation/operation/binary/unoptimized_operand/optimizable_spec.rb +38 -0
  235. data/spec/unit/veritas/optimizer/relation/operation/binary/unoptimized_operand/optimize_spec.rb +22 -0
  236. data/spec/unit/veritas/optimizer/relation/operation/combination/optimize_spec.rb +14 -0
  237. data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimizable_spec.rb +31 -0
  238. data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimize_spec.rb +16 -0
  239. data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimizable_spec.rb +25 -0
  240. data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimize_spec.rb +33 -0
  241. data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimizable_spec.rb +26 -0
  242. data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimize_spec.rb +20 -0
  243. data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimizable_spec.rb +25 -0
  244. data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimize_spec.rb +18 -0
  245. data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimizable_spec.rb +25 -0
  246. data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimize_spec.rb +19 -0
  247. data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimizable_spec.rb +26 -0
  248. data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimize_spec.rb +20 -0
  249. data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimizable_spec.rb +25 -0
  250. data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimize_spec.rb +15 -0
  251. data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimizable_spec.rb +31 -0
  252. data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimize_spec.rb +16 -0
  253. data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimizable_spec.rb +25 -0
  254. data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimize_spec.rb +20 -0
  255. data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimizable_spec.rb +26 -0
  256. data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimize_spec.rb +21 -0
  257. data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimizable_spec.rb +25 -0
  258. data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimize_spec.rb +20 -0
  259. data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimizable_spec.rb +25 -0
  260. data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimize_spec.rb +17 -0
  261. data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimizable_spec.rb +25 -0
  262. data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimize_spec.rb +22 -0
  263. data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimizable_spec.rb +20 -0
  264. data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimize_spec.rb +15 -0
  265. data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimizable_spec.rb +20 -0
  266. data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimize_spec.rb +18 -0
  267. data/spec/unit/veritas/optimizer/relation/operation/unary/operand_spec.rb +13 -0
  268. data/tasks/quality/ci.rake +2 -0
  269. data/tasks/quality/flay.rake +41 -0
  270. data/tasks/quality/flog.rake +45 -0
  271. data/tasks/quality/heckle.rake +203 -0
  272. data/tasks/quality/metric_fu.rake +26 -0
  273. data/tasks/quality/reek.rake +9 -0
  274. data/tasks/quality/roodi.rake +15 -0
  275. data/tasks/quality/yardstick.rake +23 -0
  276. data/tasks/spec.rake +38 -0
  277. data/tasks/yard.rake +9 -0
  278. data/veritas-optimizer.gemspec +550 -0
  279. metadata +613 -0
data/Gemfile ADDED
@@ -0,0 +1,33 @@
1
+ source :rubygems
2
+
3
+ gem 'veritas', '0.0.3', :git => 'git://github.com/dkubb/veritas.git'
4
+
5
+ group :development do
6
+ gem 'backports', '~> 2.1.0'
7
+ gem 'jeweler', '~> 1.5.2'
8
+ gem 'rake', '~> 0.8.7'
9
+ gem 'rspec', '~> 1.3.2'
10
+ gem 'yard', '~> 0.6.8'
11
+ end
12
+
13
+ group :jruby do
14
+ platform :jruby do
15
+ gem 'jruby-openssl', '~> 0.7.3'
16
+ end
17
+ end
18
+
19
+ platforms :mri_18 do
20
+ group :quality do
21
+ gem 'flay', '~> 1.4.2'
22
+ gem 'flog', '~> 2.5.1'
23
+ gem 'heckle', '~> 1.4.3'
24
+ gem 'json', '~> 1.5.1'
25
+ gem 'metric_fu', '~> 2.1.1'
26
+ gem 'mspec', '~> 1.5.17'
27
+ gem 'rcov', '~> 0.9.9'
28
+ gem 'reek', '~> 1.2.8', :git => 'git://github.com/dkubb/reek.git'
29
+ gem 'roodi', '~> 2.1.0'
30
+ gem 'ruby2ruby', '= 1.2.2'
31
+ gem 'yardstick', '~> 0.3.0'
32
+ end
33
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Dan Kubb
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = Veritas Optimizer
2
+
3
+ Relational algebra optimizer
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * If you want your code merged into the mainline, please discuss
8
+ the proposed changes with me before doing any work on it. This
9
+ library is still in early development, and it may not always be
10
+ clear the direction it is going. Some features may not be appropriate
11
+ yet, may need to be deferred until later when the foundation for
12
+ them is laid, or may be more applicable in a plugin.
13
+ * Fork the project.
14
+ * Make your feature addition or bug fix.
15
+ * Follow this {style guide}[https://github.com/dkubb/styleguide].
16
+ * Add specs for it. This is important so I don't break it in a
17
+ future version unintentionally. Tests must cover all branches
18
+ within the code, and code must be fully covered.
19
+ * Commit, do not mess with Rakefile, version, or history.
20
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
21
+ * Run "rake ci". This must pass and not show any regressions in the
22
+ metrics for the code to be merged.
23
+ * Send me a pull request. Bonus points for topic branches.
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2011 Dan Kubb. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'rake'
2
+
3
+ require File.expand_path('../lib/veritas/optimizer/version', __FILE__)
4
+
5
+ begin
6
+ gem('jeweler', '~> 1.5.2') if respond_to?(:gem, true)
7
+ require 'jeweler'
8
+
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = 'veritas-optimizer'
11
+ gem.summary = 'Relational algebra optimizer'
12
+ gem.description = 'Optimizes veritas relations'
13
+ gem.email = 'dan.kubb@gmail.com'
14
+ gem.homepage = 'https://github.com/dkubb/veritas-optimizer'
15
+ gem.authors = [ 'Dan Kubb' ]
16
+
17
+ gem.version = Veritas::Optimizer::VERSION
18
+ end
19
+
20
+ Jeweler::GemcutterTasks.new
21
+
22
+ FileList['tasks/**/*.rake'].each { |task| import task }
23
+ rescue LoadError
24
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.5.2'
25
+ end
data/TODO ADDED
@@ -0,0 +1,75 @@
1
+ * Add further optimizations:
2
+ * Projection
3
+ * When it contains a Rename, if the renamed attributes are projected
4
+ away, then the rename can be removed.
5
+ * Operation Order:
6
+ * Projection containing an Order
7
+ * Should remove the Order, since it is a noop
8
+ * Projection should follow Rename
9
+ * When a Projection contains a Restriction, wrap the Projection
10
+ in the Restriction, projecting away any attributes not used in
11
+ the restriction. If there are any remaining attributes, then
12
+ wrap the operation in a Projection removing those attributes.
13
+ * If all attributes are being used in the Restriction do nothing
14
+ * When a Projection contains a Join, wrap the Join with a Projection
15
+ of all the headers, minus those used in the Join. If there were
16
+ any used, then wrap the whole operation in a Projection with
17
+ the remaining attributes.
18
+ * If all the attributes are used in the Join, do nothing
19
+ * Try to use the same approach for Product
20
+ * Test if it's possible to fully distribute projections over
21
+ joins rather than splitting it up like this.
22
+ * Restriction should follow Projection
23
+ * Restriction optimizations:
24
+ * "attr > ? OR attr > ?" -> "attr > ?", with the least restrictive value
25
+ * Do the same for >=, <, <=
26
+ * "attr > ? AND attr > ?" -> "attr > ?", with the most restrictive value
27
+ * Do the same for >=, <, <=
28
+ * "attr > 5 OR attr == 5" -> "attr >= 5"
29
+ * "attr < 5 OR attr == 5" -> "attr <= 5"
30
+ * "attr" = "string" AND "attr" =~ /string/ -> "attr" = "string"
31
+ * If the regexp matches the constant, then it should be
32
+ optimized down to a constant match. If it does not match
33
+ then it should be optimized to a Contradiction.
34
+ * Constant folding, eg:
35
+ "attr1 > attr2 AND attr1 = 5" -> "5 > attr2 AND attr1 = 5"
36
+ * This will probably only work across Conjunctions.
37
+ * "attr > 5 AND attr = 6" -> "attr = 6", because attr must be
38
+ equal to 6. this will probably be related to constant folding;
39
+ the first expression will become 6 > 5, which evaluates to a
40
+ Tautology, then the expression is a Tautology AND attr = 6,
41
+ which simplifies down to attr = 6.
42
+ * "attr < 5 AND attr = 6" -> "Contradiction", because attr must be equal to
43
+ 6, and 6 < 5 evaluates to a Contradiction. A Contradiction AND attr = 6
44
+ simplifies down to a Contradiction.
45
+ * Figure out how to reorganize the Restriction predicates so that all
46
+ similar operations are closer together to allow more efficient
47
+ optimizations. This would allow optimizations of stuff like this:
48
+
49
+ "attr1 = ? OR attr2 = ? OR attr1 = ?"
50
+
51
+ Into:
52
+
53
+ "attr1 IN(..) OR attr2 = ?"
54
+ * Rename should distribute over Join, Product and Set operations
55
+ * The goal should be to push Rename as close to the base tables
56
+ as possible so that the names of attribute will be consistent
57
+ throughout the whole tree.
58
+ * A Union of relations with the same base, header, and restrictions should
59
+ try to combine into a single relation with the restrictions using OR.
60
+ * An Intersection of relations with the same base, header, and restrictions
61
+ should try to combine into a single relation with the restrictions using
62
+ AND.
63
+ * A Difference of relations with the same base and restrictions should
64
+ try to combine into a single relation with the restrictions using NOT.
65
+ * Join Optimizations
66
+ * When a Join contains a Join, and the size of the base relations is
67
+ known, join the smallest with the largest, and then join that result
68
+ with the remaining relation.
69
+ * Make sure the smallest relation (with a known size) is always the
70
+ right-most operation.
71
+ * When a restriction uses a unique index:
72
+ * Order can be factored out
73
+ * Limit with a limit >= 1 can be factored out
74
+ * Offset with an offset > 0 can be transformed into an empty
75
+ relation, since at most there can be only one match.
data/config/flay.yml ADDED
@@ -0,0 +1,3 @@
1
+ ---
2
+ threshold: 131
3
+ total_score: 905
data/config/flog.yml ADDED
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 12.4
data/config/roodi.yml ADDED
@@ -0,0 +1,16 @@
1
+ ---
2
+ AbcMetricMethodCheck: { score: 7.3 }
3
+ AssignmentInConditionalCheck: { }
4
+ CaseMissingElseCheck: { }
5
+ ClassLineCountCheck: { line_count: 390 }
6
+ ClassNameCheck: { pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/ }
7
+ ClassVariableCheck: { }
8
+ CyclomaticComplexityBlockCheck: { complexity: 2 }
9
+ CyclomaticComplexityMethodCheck: { complexity: 6 }
10
+ EmptyRescueBodyCheck: { }
11
+ ForLoopCheck: { }
12
+ MethodLineCountCheck: { line_count: 9 }
13
+ MethodNameCheck: { pattern: !ruby/regexp /\A(?:[a-z](?:_?[a-z])+[?!=]?|\[\]=?|==|<=>|[+*&|-])\z/ }
14
+ ModuleLineCountCheck: { line_count: 392 }
15
+ ModuleNameCheck: { pattern: !ruby/regexp /\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/ }
16
+ ParameterNumberCheck: { parameter_count: 3 }
data/config/site.reek ADDED
@@ -0,0 +1,91 @@
1
+ ---
2
+ UncommunicativeParameterName:
3
+ accept: []
4
+ exclude: []
5
+ enabled: true
6
+ reject:
7
+ - !ruby/regexp /^.$/
8
+ - !ruby/regexp /[0-9]$/
9
+ - !ruby/regexp /[A-Z]/
10
+ LargeClass:
11
+ max_methods: 11 # TODO: decrease max_methods to 10-15 or less
12
+ exclude: []
13
+ enabled: true
14
+ max_instance_variables: 2
15
+ UncommunicativeMethodName:
16
+ accept: []
17
+ exclude: []
18
+ enabled: true
19
+ reject:
20
+ - !ruby/regexp /^[a-z]$/
21
+ - !ruby/regexp /[0-9]$/
22
+ - !ruby/regexp /[A-Z]/
23
+ LongParameterList:
24
+ max_params: 3
25
+ exclude: []
26
+ enabled: true
27
+ overrides: {}
28
+ FeatureEnvy:
29
+ exclude: []
30
+ enabled: true
31
+ ClassVariable:
32
+ exclude: []
33
+ enabled: true
34
+ BooleanParameter:
35
+ exclude: []
36
+ enabled: true
37
+ IrresponsibleModule:
38
+ exclude: []
39
+ enabled: true
40
+ UncommunicativeModuleName:
41
+ accept: []
42
+ exclude: []
43
+ enabled: true
44
+ reject:
45
+ - !ruby/regexp /^.$/
46
+ - !ruby/regexp /[0-9]$/
47
+ NestedIterators:
48
+ ignore_iterators: []
49
+ exclude: []
50
+ enabled: true
51
+ max_allowed_nesting: 1
52
+ LongMethod:
53
+ max_statements: 7
54
+ exclude: []
55
+ enabled: true
56
+ Duplication:
57
+ allow_calls: []
58
+ exclude: []
59
+ enabled: true
60
+ max_calls: 1
61
+ UtilityFunction:
62
+ max_helper_calls: 1
63
+ exclude: []
64
+ enabled: true
65
+ Attribute:
66
+ exclude: []
67
+ enabled: false
68
+ UncommunicativeVariableName:
69
+ accept: []
70
+ exclude: []
71
+ enabled: true
72
+ reject:
73
+ - !ruby/regexp /^.$/
74
+ - !ruby/regexp /[0-9]$/
75
+ - !ruby/regexp /[A-Z]/
76
+ SimulatedPolymorphism:
77
+ exclude: []
78
+ enabled: true
79
+ max_ifs: 1
80
+ DataClump:
81
+ exclude: []
82
+ enabled: true
83
+ max_copies: 1
84
+ min_clump_size: 2
85
+ ControlCouple:
86
+ exclude: []
87
+ enabled: true
88
+ LongYieldList:
89
+ max_params: 1
90
+ exclude: []
91
+ enabled: true
@@ -0,0 +1,2 @@
1
+ ---
2
+ threshold: 100
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Algebra
6
+
7
+ # Abstract base class representing Difference optimizations
8
+ class Difference < Relation::Operation::Binary
9
+
10
+ # Optimize when operands are equal
11
+ class EqualOperands < self
12
+ include Relation::Operation::Binary::EqualOperands
13
+
14
+ # A Difference with equal operands is empty
15
+ #
16
+ # @return [Relation::Empty]
17
+ #
18
+ # @api private
19
+ def optimize
20
+ Veritas::Relation::Empty.new(operation.header)
21
+ end
22
+
23
+ end # class EqualOperands
24
+
25
+ # Optimize when the left operand is empty
26
+ class EmptyLeft < self
27
+ include Relation::Operation::Binary::EmptyLeft
28
+
29
+ # A Difference with an empty left operand is empty
30
+ #
31
+ # @return [Relation::Empty]
32
+ #
33
+ # @api private
34
+ def optimize
35
+ left
36
+ end
37
+
38
+ end # class EmptyLeft
39
+
40
+ # Optimize when the right operand is empty
41
+ class EmptyRight < self
42
+ include Relation::Operation::Binary::EmptyRight
43
+
44
+ # A Difference with an empty right operand is equivalent to the left
45
+ #
46
+ # @return [Relation]
47
+ #
48
+ # @api private
49
+ def optimize
50
+ left
51
+ end
52
+
53
+ end # class EmptyRight
54
+
55
+ Veritas::Algebra::Difference.optimizer = chain(
56
+ EqualOperands,
57
+ EmptyLeft,
58
+ EmptyRight,
59
+ MaterializedOperand,
60
+ UnoptimizedOperand
61
+ )
62
+
63
+ end # class Difference
64
+ end # module Algebra
65
+ end # class Optimizer
66
+ end # module Veritas
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Algebra
6
+
7
+ # Abstract base class representing Extension optimizations
8
+ class Extension < Relation::Operation::Unary
9
+
10
+ # Optimize when operands are optimizable
11
+ class UnoptimizedOperand < self
12
+
13
+ # Test if the operand is unoptimized
14
+ #
15
+ # @return [Boolean]
16
+ #
17
+ # @api private
18
+ def optimizable?
19
+ !operand.equal?(operation.operand)
20
+ end
21
+
22
+ # Return an Extension with an optimized operand
23
+ #
24
+ # @return [Algebra::Extension]
25
+ #
26
+ # @api private
27
+ def optimize
28
+ operation = self.operation
29
+ operation.class.new(operand, operation.extensions)
30
+ end
31
+
32
+ end # class UnoptimizedOperand
33
+
34
+ Veritas::Algebra::Extension.optimizer = chain(
35
+ MaterializedOperand,
36
+ UnoptimizedOperand
37
+ )
38
+
39
+ end # class Extension
40
+ end # module Algebra
41
+ end # class Optimizer
42
+ end # module Veritas
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Algebra
6
+
7
+ # Abstract base class representing Intersection optimizations
8
+ class Intersection < Relation::Operation::Binary
9
+
10
+ # Optimize when operands are equal
11
+ class EqualOperands < self
12
+ include Relation::Operation::Binary::EqualOperands
13
+
14
+ # An Intersection with equal operands is equivalent to either operand
15
+ #
16
+ # @return [Relation]
17
+ #
18
+ # @api private
19
+ def optimize
20
+ left
21
+ end
22
+
23
+ end # class EqualOperands
24
+
25
+ # Optimize when the left operand is empty
26
+ class EmptyLeft < self
27
+ include Relation::Operation::Binary::EmptyLeft
28
+
29
+ # An Intersection with an empty left operand is empty
30
+ #
31
+ # @return [Relation::Empty]
32
+ #
33
+ # @api private
34
+ def optimize
35
+ left
36
+ end
37
+
38
+ end # class EmptyLeft
39
+
40
+ # Optimize when the right operand is empty
41
+ class EmptyRight < self
42
+ include Relation::Operation::Binary::EmptyRight
43
+
44
+ # An Intersection with an empty right operand is empty
45
+ #
46
+ # @return [Relation::Empty]
47
+ #
48
+ # @api private
49
+ def optimize
50
+ right
51
+ end
52
+
53
+ end # class EmptyRight
54
+
55
+ Veritas::Algebra::Intersection.optimizer = chain(
56
+ EqualOperands,
57
+ EmptyLeft,
58
+ EmptyRight,
59
+ MaterializedOperand,
60
+ UnoptimizedOperand
61
+ )
62
+
63
+ end # class Intersection
64
+ end # module Algebra
65
+ end # class Optimizer
66
+ end # module Veritas
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Algebra
6
+
7
+ # Abstract base class representing Join optimizations
8
+ class Join < Relation::Operation::Combination
9
+
10
+ # Optimize when operand headers are equivalent
11
+ class EqualHeaders < self
12
+
13
+ # Test if the operands' headers are equal
14
+ #
15
+ # @return [Boolean]
16
+ #
17
+ # @api private
18
+ def optimizable?
19
+ left.header.eql?(right.header)
20
+ end
21
+
22
+ # A Join with equal headers is an Intersection
23
+ #
24
+ # @return [Algebra::Intersection]
25
+ #
26
+ # @api private
27
+ def optimize
28
+ Veritas::Algebra::Intersection.new(left, right)
29
+ end
30
+
31
+ end # class EqualHeaders
32
+
33
+ Veritas::Algebra::Join.optimizer = chain(
34
+ EmptyLeft,
35
+ EmptyRight,
36
+ EqualHeaders,
37
+ MaterializedOperand,
38
+ UnoptimizedOperand
39
+ )
40
+
41
+ end # class Join
42
+ end # module Algebra
43
+ end # class Optimizer
44
+ end # module Veritas
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Algebra
6
+
7
+ # Abstract base class representing Product optimizations
8
+ class Product < Relation::Operation::Combination
9
+
10
+ # Optimize when left operand is a TABLE DEE
11
+ class TableDeeLeft < self
12
+
13
+ # Test if the left operand is a TABLE DEE
14
+ #
15
+ # @return [Boolean]
16
+ #
17
+ # @api private
18
+ def optimizable?
19
+ left = self.left
20
+ left.header.empty? && !left.kind_of?(Veritas::Relation::Empty)
21
+ end
22
+
23
+ # A Product with a left TABLE DEE is equivalent to the right operand
24
+ #
25
+ # @return [Relation]
26
+ #
27
+ # @api private
28
+ def optimize
29
+ right
30
+ end
31
+
32
+ end # class TableDeeLeft
33
+
34
+ # Optimize when right operand is a TABLE DEE
35
+ class TableDeeRight < self
36
+
37
+ # Test if the right operand is a TABLE DEE
38
+ #
39
+ # @return [Boolean]
40
+ #
41
+ # @api private
42
+ def optimizable?
43
+ right = self.right
44
+ right.header.empty? && !right.kind_of?(Veritas::Relation::Empty)
45
+ end
46
+
47
+ # A Product with a right TABLE DEE is equivalent to the left operand
48
+ #
49
+ # @return [Relation]
50
+ #
51
+ # @api private
52
+ def optimize
53
+ left
54
+ end
55
+
56
+ end # class TableDeeRight
57
+
58
+ Veritas::Algebra::Product.optimizer = chain(
59
+ TableDeeLeft,
60
+ TableDeeRight,
61
+ EmptyLeft,
62
+ EmptyRight,
63
+ MaterializedOperand,
64
+ UnoptimizedOperand
65
+ )
66
+
67
+ end # class Product
68
+ end # module Algebra
69
+ end # class Optimizer
70
+ end # module Veritas