Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,17 @@ abstract class UnaryNode extends LogicalPlan {
* expressions with the corresponding alias
*/
protected def getAliasedConstraints(projectList: Seq[NamedExpression]): Set[Expression] = {
var allConstraints = child.constraints.asInstanceOf[Set[Expression]]
val relativeReferences = AttributeSet(projectList.collect {
case a: Alias => a
}.flatMap(_.references)) ++ outputSet

// We only care about the constraints which refer to attributes in output and aliases.
// For example, for a constraint 'a > b', if 'a' is aliased to 'c', we need to get aliased
// constraint 'c > b' only if 'b' is in output.
var allConstraints = child.constraints.filter { constraint =>
constraint.references.subsetOf(relativeReferences)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @viirya, I understand that #16998 probably supersedes this, but just out of curiosity, did you see a lot of benefit from pruning these attributes here given that we already prune them later in QueryPlan?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. You can see the benchmark in the pr description. With pruning these attributes, the running time is cut half.

If I understand your comment correctly, pruning them later in QueryPlan means we prune constraints which don't refer attributes in outputSet.

But the pruning here is happened before the pruning you pointed out, we need to reduce the constraints taken for transforming aliasing attributes to lower the computation cost.

}.asInstanceOf[Set[Expression]]

projectList.foreach {
case a @ Alias(e, _) =>
// For every alias in `projectList`, replace the reference in constraints by its attribute.
Expand Down