Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
When a subset is registered, registerImpl() and registerSubset() currently simply returns the subset itself. The problem is that subset can become stale when relSets get merged (for example in ensureRegistered() and registerSubset() "merge(set, subset.set)"). As a result, a stale/merged subset might be returned from registerImpl, and the newly registering subtree might get registered recursively on top of the stale subset (see AbstractRelNode.onRegister()). This is a leak because once a relSet/subset is merged into others and becomes stale, it should not be used to connect new relNodes.
With CALCITE-3755, subsets can now be directly matched by rules. This opens another source of stale subset leak: (1) An active subset gets matched, the RuleMatch gets queued in RuleQueue. (2) The subset becomes stale due to relSet merge. (3) The rule match in (1) is popped from queue and fired. (4) In OnMatch the rule gets the stale subset, builds new rels on top of it and regsiter the new rels. In this case, the entire new rel subtree will be registered on top of the stale subset as is.
Rather than returning the registering subset itself, register should always use canonize() to find and return the equivalent active subset instead.