yql_cost_function.h 1.8 KB

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