yql_cost_function.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #pragma once
  2. #include "yql_statistics.h"
  3. #include <util/generic/hash.h>
  4. #include <util/generic/vector.h>
  5. #include <util/generic/string.h>
  6. #include <set>
  7. /**
  8. * The cost function for cost based optimizer currently consists of methods for computing
  9. * both the cost and cardinalities of individual plan operators
  10. */
  11. namespace NYql {
  12. struct IProviderContext;
  13. enum class EJoinAlgoType {
  14. Undefined,
  15. LookupJoin,
  16. LookupJoinReverse,
  17. MapJoin,
  18. GraceJoin,
  19. StreamLookupJoin, //Right part can be updated during an operation. Used mainly for joining streams with lookup tables. Currently impplemented in Dq by LookupInputTransform
  20. MergeJoin // To be used in YT
  21. };
  22. //StreamLookupJoin is not a subject for CBO and not not included here
  23. static constexpr auto AllJoinAlgos = { EJoinAlgoType::LookupJoin, EJoinAlgoType::LookupJoinReverse, EJoinAlgoType::MapJoin, EJoinAlgoType::GraceJoin, EJoinAlgoType::MergeJoin };
  24. namespace NDq {
  25. /**
  26. * Join column is a struct that records the relation label and
  27. * attribute name, used in join conditions
  28. */
  29. struct TJoinColumn {
  30. TString RelName{};
  31. TString AttributeName{};
  32. TString AttributeNameWithAliases{};
  33. std::optional<ui32> EquivalenceClass{};
  34. bool IsConstant = false;
  35. TJoinColumn(TString relName, TString attributeName) :
  36. RelName(relName),
  37. AttributeName(attributeName),
  38. AttributeNameWithAliases(attributeName) {}
  39. bool operator == (const TJoinColumn& other) const {
  40. return RelName == other.RelName && AttributeName == other.AttributeName;
  41. }
  42. struct THashFunction
  43. {
  44. size_t operator()(const TJoinColumn& c) const
  45. {
  46. return THash<TString>{}(c.RelName) ^ THash<TString>{}(c.AttributeName);
  47. }
  48. };
  49. };
  50. bool operator < (const TJoinColumn& c1, const TJoinColumn& c2);
  51. } // namespace NDq
  52. } // namespace NYql