code: func (b *PlanBuilder) divideUnionSelectPlans(selects []*ast.SelectStmt) (distinctSelects []LogicalPlan, allSelects []LogicalPlan, err error) {
  	firstUnionAllIdx, columnNums := 0, -1
  	// The last slot is reserved for appending distinct union outside this function.
  	children := make([]LogicalPlan, len(selects), len(selects)+1)
  	for i := len(selects) - 1; i >= 0; i-- {
  		stmt := selects[i]
  		if firstUnionAllIdx == 0 && stmt.IsAfterUnionDistinct {
  			firstUnionAllIdx = i + 1
  		}
  
  		selectPlan, err := b.buildSelect(stmt)
  		if err != nil {
  			return nil, nil, err
  		}
  
  		if columnNums == -1 {
  			columnNums = selectPlan.Schema().Len()
  		}
  		if selectPlan.Schema().Len() != columnNums {
  			return nil, nil, ErrWrongNumberOfColumnsInSelect.GenWithStackByArgs()
  		}
  		children[i] = selectPlan
  	}
  	return children[:firstUnionAllIdx], children[firstUnionAllIdx:], nil
  }
docs: // divideUnionSelectPlans resolves union's select stmts to logical plans.
  // and divide result plans into "union-distinct" and "union-all" parts.
  // divide rule ref: https://dev.mysql.com/doc/refman/5.7/en/union.html
  // "Mixed UNION types are treated such that a DISTINCT union overrides any ALL union to its left."