IP Library › Granted Patent US 12,353,412
Granted Patent B2
US 12,353,412 · App. 18/473,752 · Granted Jul 8, 2025

Runtime statistics feedback for query plan cost estimation

Inventors: Jaehyok Chong (Seoul, KR); Young Goo Cho (Seoul, KR); Ki Hong Kim (Seoul, KR)
Assignee: SAP SE
G06F16/24542G06F16/2246G06F16/24573G06F16/284
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,353,412
App. No.
18/473,752
Granted
Jul 8, 2025
Kind
B2
Abstract

A computer implemented method can execute a first query plan for a query, obtain statistics for internal nodes of a first query tree representing the first query plan, receive a second query tree representing a second query plan for the query, search for a matching internal node of the first query tree for a selected internal node of the second query tree, and responsive to finding the matching internal node of the first query tree, apply 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. Related systems and software for implementing the method are also disclosed.

Claims (72)

1. A computer-implemented method comprising:

executing a first query plan for a query;

obtaining statistics for one or more internal nodes of a first query tree representing the first query plan during execution of the first query plan;

mapping keys which uniquely identify the one or more internal nodes of the first query tree to respective statistics;

receiving a second query tree representing a second query plan for the query after execution of the first query plan has completed 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 executing the second query plan to complete the query,

wherein the keys comprise respective signatures for operations represented by the one or more internal nodes, wherein a signature comprises an operator and one or more operands defined by a corresponding operation.

2. The computer-implemented method of claim 1 , wherein obtaining statistics for an internal node of the first query tree comprises determining a cardinality of a table resulted from an operation represented by the internal node after executing the first query plan.

3. The computer-implemented method of claim 1 , further comprising registering the keys in a dictionary.

4. The computer-implemented method of claim 3 , wherein searching for the matching internal node comprises:

generating a target key for the selected internal node of the second query tree; and

searching the dictionary for a key that matches the target key.

5. The computer-implemented method of claim 3 , wherein searching for the matching internal node comprises:

selecting 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.

6. The computer-implemented method of claim 3 , further comprising:

responsive to executing the second query plan as a result of query optimization of the query, obtaining statistics for one or more internal nodes of the second query tree;

identifying an unmatched internal node of the second query tree that has no matching internal node of the first query tree;

generating a new key uniquely identifying the unmatched internal node;

registering the new key in the dictionary; and

mapping the new key to the statistics for the unmatched internal node of the second query tree.

7. The computer-implemented method of claim 3 , further comprising:

responsive to executing the second query plan as a result of query optimization of the query, obtaining statistics for one or more internal nodes of the second query tree;

finding a matching key in the dictionary identifying the matching internal node of the first query tree corresponding to the selected internal node of the second query tree; and

mapping the matching key to the statistics for the selected internal node of the second query tree.

8. The computer-implemented method of claim 1 , wherein the keys further identify respective child nodes of the one or more internal nodes.

9. The computer-implemented method of claim 1 , wherein at least a portion of the signature is represented by a hash value.

10. The computer-implemented method of claim 1 , further comprising:

identifying a first internal node and a second internal node of the second query tree, wherein the first internal node represents a group-by operation having a known selectivity, wherein the second internal node represents a pre-aggregation of the group-by operation represented by the first internal node; and

applying the known selectivity of the first internal node to the second internal node.

11. A computing system, comprising:

memory;

one or more hardware processors coupled to the memory; and

one or more computer readable storage media storing instructions that, when loaded into the memory, cause the one or more hardware processors to perform operations comprising:

executing a first query plan for a query;

obtaining statistics for one or more internal nodes of a first query tree representing the first query plan during execution of the first query plan;

mapping keys which uniquely identify the one or more internal nodes of the first query tree to respective statistics;

receiving a second query tree representing a second query plan for the query after execution of the first query plan has completed 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 executing the second query plan to complete the query,

wherein the keys comprise respective signatures for operations represented by the one or more internal nodes, wherein a signature comprises an operator and one or more operands defined by a corresponding operation.

12. The computing system of claim 11 , wherein the statistics for an internal node of the first query tree comprises a cardinality of a table resulted from an operation represented by the internal node after executing the first query plan.

13. The computing system of claim 11 , wherein the operations further registering the keys in a dictionary.

14. The computing system of claim 13 , wherein searching for the matching internal node comprises:

generating a target key for the selected internal node of the second query tree; and

searching the dictionary for a key that matches the target key.

15. The computing system of claim 13 , wherein searching for the matching internal node comprises:

selecting 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.

16. The computing system of claim 13 , wherein the operations further comprise:

responsive to executing the second query plan as a result of query optimization of the query, obtaining statistics for one or more internal nodes of the second query tree;

identifying an unmatched internal node of the second query tree that has no matching internal node of the first query tree;

generating a new key uniquely identifying the unmatched internal node;

registering the new key in the dictionary; and

mapping the new key to the statistics for the unmatched internal node of the second query tree.

17. The computing system of claim 13 , wherein the operations further comprise:

responsive to executing the second query plan as a result of query optimization of the query, obtaining statistics for one or more internal nodes of the second query tree;

finding a matching key in the dictionary identifying the matching internal node of the first query tree corresponding to the selected internal node of the second query tree; and

mapping the matching key to the statistics for the selected internal node of the second query tree.

18. The computing system of claim 11 , wherein the keys further identify respective child nodes of the one or more internal nodes.

19. The computing system of claim 11 , wherein at least a portion of the signature is represented by a hash value.

20. One or more non-transitory computer-readable media having encoded thereon computer-executable instructions causing one or more processors to perform a method comprising:

executing a first query plan for a query;

obtaining cardinalities for one or more internal nodes of a first query tree representing the first query plan during execution of the first query plan;

mapping keys which uniquely identify the one or more internal nodes of the first query tree to respective statistics;

receiving a second query tree representing a second query plan for the query after execution of the first query plan has completed 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 a cardinality for the matching internal node of the first query tree to the selected internal node of the second query tree for estimating cost of executing the second query plan to complete the query,

wherein the keys comprise respective signatures for operations represented by the one or more internal nodes, wherein a signature comprises an operator and one or more operands defined by a corresponding operation.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Oct 11, 2023
From: CHONG, JAEHYOK; CHO, YOUNG GOO; KIM, KI HONG
To: SAP SE
Reel/Frame 065187/0446 →
Continuity (2)
Continuation 17849446 · Jun 24, 2022
Related Publication 20240012814A1 · Jan 11, 2024
References Cited (25)
US 11860869B1 · Hwang · 2024 [cited by examiner]
US 20040015478A1 · Pauly · 2004 [cited by examiner]
US 20040225639A1 · Jakobsson · 2004 [cited by examiner]
US 20060248046A1 · Galindo-Legaria · 2006 [cited by examiner]
US 20080133458A1 · Zabback · 2008 [cited by examiner]
US 20080253306A1 · Manion · 2008 [cited by examiner]
US 20090327214A1 · Richardson · 2009 [cited by examiner]
US 20100145929A1 · Burger · 2010 [cited by examiner]
US 20110029508A1 · Al-Omari · 2011 [cited by examiner]
US 20150006509A1 · Shao · 2015 [cited by examiner]
US 20180124048A1 · Yoo · 2018 [cited by examiner]
Extended European Search Report for European Application No. 23178833.2, dated Nov. 8, 2023, 9 pages. [cited by applicant]
“Canonical Form,” Wikipedia, https://en.wikipedia.org/wiki/Canonical_form, printed Mar. 8, 2022, 7 pages. [cited by applicant]
Chaudhuri, et al., “Evaluating Top-k Selection Queries,” Proceedings of the 25 [cited by applicant]
Moerkotte, et al., “On the Correct and Complete Enumeration of the Core Search Space,” [cited by applicant]
“Notations for the Physical Query Plan,” http://www.mathcs.emory.edu/˜cheung/Courses/554/Syllabus/5-query-opt/notations.html#:˜:text=Physical, printed May 16, 2022, 5 pages. [cited by applicant]
“Overview: Query Optimization,” www.mathcs.emory.edu/˜cheung/Courses/554/Syllabus/5-query-opt/intro.html, printed May 16, 2022, 4 pages. [cited by applicant]
“Queries for DFS of a subtree in a tree,” https://www.geeksforgeeks.org/queries-for-dfs-of-a-subtree-in-a-tree/, printed May 12, 2022, 18 pages. [cited by applicant]
“Query Optimization in Centralized Systems,” https://www.tutorialspoint.com/distributed_dbms/distributed_dbms_query_optimization_centralized_systems.htm, printed Mar. 8, 2022, 3 pages. [cited by applicant]
“Query rewriting methods and examples,” IBM Documentation, https://www.ibm.com/docs/en/db2/10.5?topic=process-query-rewriting-methods-examples, printed May 16, 2022, 3 pages. [cited by applicant]
“Relational Algebra for Query Optimization,” https://www.tutorialspoint.com/distributed_dbms/distributed_dbms_relational_algebra_query_optimization.htm, printed Mar. 8, 2022, 8 pages. [cited by applicant]
“Search Normalization,” Splunk Documentation, https://docs.splunk.com/Documentation/Splunk/8.2.6/Search/Searchnormalization, printed May 18, 2022, 5 pages. [cited by applicant]
“SQL/Group by,” GeeksforGeeks, https://www.geeksforgeeks.org/sql-group-by/, printed May 10, 2022, 8 pages. [cited by applicant]
“String.prototype.normalize()—JavaScript,” MDN, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize, printed May 11, 2022, 5 pages. [cited by applicant]
“Subtree of all nodes in a tree using DFS,” GeeksforGeeks, https://www.geeksforgeeks.org/sub-tree-nodes-tree-using-dfs/, printed May 12, 2022, 15 pages. [cited by applicant]