quickstep-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zuyu <...@git.apache.org>
Subject [GitHub] incubator-quickstep pull request #237: QUICKSTEP-89 Add support for common s...
Date Sun, 23 Apr 2017 22:25:26 GMT
Github user zuyu commented on a diff in the pull request:

    https://github.com/apache/incubator-quickstep/pull/237#discussion_r112828399
  
    --- Diff: query_optimizer/expressions/Scalar.hpp ---
    @@ -65,10 +67,49 @@ class Scalar : public Expression {
           const std::unordered_map<ExprId, const CatalogAttribute*>& substitution_map)
           const = 0;
     
    +  /**
    +   * @brief Check whether this scalar is semantically equivalent to \p other.
    +   *
    +   * @note The fact that two scalars are semantically equal brings more
    +   *       optimization opportunities, e.g. common subexpression elimination.
    +   *       Meanwhile, it is always safe to assume that two scalars are not equal.
    +   *
    +   * @return True if this scalar equals \p other; false otherwise.
    +   */
    +  virtual bool equals(const ScalarPtr &other) const {
    +    return false;
    +  }
    +
    +  /**
    +   * @brief Get a hash of this scalar.
    +   *
    +   * @return A hash of this scalar.
    +   */
    +  std::size_t hash() const {
    +    if (hash_cache_ == nullptr) {
    +      hash_cache_ = std::make_unique<std::size_t>(computeHash());
    +    }
    +    return *hash_cache_;
    --- End diff --
    
    What do you think if we define `hash_cache_` as a `std::uint64_t` so that we save a pointer
reference?
    
    Thus, if its value is `0`, we compute the hash value. Otherwise, return the value.
    
    FYI, sizeof `std::size_t` depends on the system implementation, so I suggest to the 64-bit
integer instead.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message