A computer-implemented method comprising: executing a first query plan for a query; obtaining statistics for one or more internal nodes (322, 323) of a first query tree representing the first query plan; receiving a second query tree representing a second query plan for the query; for a selected internal node of the second query tree, searching for a matching internal node out of the one or more internal nodes of the first query tree; and responsive to finding the matching internal node of the first query tree, applying the statistics for the matching internal node of the first query tree to the selected internal node of the second query tree for estimating cost of the second query plan during query optimization of the query; further comprising: generating keys uniquely identifying the one or more internal nodes of the first query tree; registering the keys in a dictionary; and mapping the keys to respective statistics for the one or more internal nodes of the first query tree; wherein searching for the matching internal node comprises: using an equivalence rule to select an alternative subtree that is logically equivalent to a subtree of the selected internal node of the second query tree; generating a target key for a root of the alternative subtree; and searching the dictionary for a key that matches the target key. executing a first query plan for a query; obtaining statistics for one or more internal nodes (322, 323) of a first query tree representing the first query plan; receiving a second query tree representing a second query plan for the query; for a selected internal node of the second query tree, searching for a matching internal node out of the one or more internal nodes of the first query tree; and responsive to finding the matching internal node of the first query tree, applying the statistics for the matching internal node of the first query tree to the selected internal node of the second query tree for estimating cost of the second query plan during query optimization of the query; further comprising: generating keys uniquely identifying the one or more internal nodes of the first query tree; registering the keys in a dictionary; and mapping the keys to respective statistics for the one or more internal nodes of the first query tree; wherein searching for the matching internal node comprises: using an equivalence rule to select an alternative subtree that is logically equivalent to a subtree of the selected internal node of the second query tree; generating a target key for a root of the alternative subtree; and searching the dictionary for a key that matches the target key. generating keys uniquely identifying the one or more internal nodes of the first query tree; registering the keys in a dictionary; and mapping the keys to respective statistics for the one or more internal nodes of the first query tree; wherein searching for the matching internal node comprises: using an equivalence rule to select an alternative subtree that is logically equivalent to a subtree of the selected internal node of the second query tree; generating a target key for a root of the alternative subtree; and searching the dictionary for a key that matches the target key. using an equivalence rule to select an alternative subtree that is logically equivalent to a subtree of the selected internal node of the second query tree; generating a target key for a root of the alternative subtree; and searching the dictionary for a key that matches the target key.