IP Library › Granted Patent US 12,585,647
Granted Patent B2
US 12,585,647 · App. 18/746,516 · Granted Mar 24, 2026

Query execution system with plan reuse

Inventors: Christian Bensberg (Heidelberg, DE); Johannes Merx (Heidelberg, DE)
Assignee: SAP SE
G06F16/24524G06F16/24549
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,585,647
App. No.
18/746,516
Filed
Jun 18, 2024
Granted
Mar 24, 2026
Kind
B2
Art Unit
2154
USPC
707/714
Abstract

System, method, and various embodiments for a query execution system with plan reuse are described herein. An embodiment operates by receiving a query on a database, the received query comprising one or more constants. Normalization is performed on the query, replacing the one or more constants with a variable-indicator. The normalized query is compared to one or more previously executed queries to identify a matching query. A matching execution plan corresponding to the matching query is selected. The matching execution plan is executed, for which the one or more constants are provided as runtime variables. A result from the execution of the matching execution plan is generated and returned.

Claims (85)

1 . A computer-implemented method comprising:

receiving a query on a database, the query comprising one or more first constants;

performing normalization on the query to generate a normalized query, the normalization comprising replacing the one or more first constants with a variable-indicator;

comparing the normalized query to one or more previously generated normalized queries to identify a matching query of the one or more previously generated normalized queries, wherein the matching query corresponds to a previously received query comprising one or more second constants;

selecting a matching execution plan of one or more previously saved execution plans, based on the matching execution plan corresponding to the matching query, wherein each of the one or more previously saved execution plans is pre-compiled;

executing the matching execution plan, for the query, on the database, wherein the executing comprises providing the one or more first constants as runtime variables;

generating a result from the execution of the matching execution plan; and

returning the result as a result of the query.

2 . The computer-implemented method of claim 1 , wherein the executing further comprises:

performing a selectivity comparison between the one or more second constants of the previously received query and the one or more first constants of the query;

determining that a first selectivity of the one or more first constants of the query fall within a range of a second selectivity of the one or more second constants of the previously received query; and

selecting the matching execution plan based on the determination.

3 . The computer-implemented method of claim 1 , wherein the executing further comprises:

performing a selectivity comparison between the one or more second constants of the previously received query and the one or more first constants of the query;

determining that a first selectivity of the one or more first constants of the query fall outside a range of a second selectivity of the one or more second constants of the previously received query;

recompiling the matching execution plan in view of the determination; and

executing the recompiled matching execution plan.

4 . The computer-implemented method of claim 1 , wherein the comparing comprises:

comparing a first table of the normalized query to a second table of the matching query to determine that the first table is identical to the second table.

5 . The computer-implemented method of claim 4 , further comprising:

comparing one or more first fields of the normalized query to one or more second fields of the matching query to determine that the one or more first fields are identical to the one or more second fields.

6 . The computer-implemented method of claim 1 , wherein the performing normalization comprises:

identifying an OR statement between a first value and a second value in the query;

removing the OR statement; and

replacing the first value and the second value with the variable-indicator.

7 . The computer-implemented method of claim 1 , wherein the performing normalization comprises:

identifying an AND statement between a first field and a second field in the query; and

sorting the first field and the second field alphabetically.

8 . A system comprising:

a memory; and

at least one processor coupled to the memory and configured to perform operations comprising:

receiving a query on a database, the query comprising one or more first constants;

performing normalization on the query to generate a normalized query, the normalization comprising replacing the one or more first constants with a variable-indicator;

comparing the normalized query to one or more previously generated normalized queries to identify a matching query of the one or more previously generated normalized queries, wherein the matching query corresponds to a previously received query comprising one or more second constants;

selecting a matching execution plan of one or more previously saved execution plans, based on the matching execution plan corresponding to the matching query, wherein each of the one or more previously saved execution plans is pre-compiled;

executing the matching execution plan, for the query, on the database, wherein the executing comprises providing the one or more first constants as runtime variables;

generating a result from the execution of the matching execution plan; and

returning the result as a result of the query.

9 . The system of claim 8 , wherein the executing further comprises:

performing a selectivity comparison between the one or more second constants of the previously received query and the one or more first constants of the query;

determining that a first selectivity of the one or more first constants of the query fall within a range of a second selectivity of the one or more second constants of the previously received query; and

selecting the matching execution plan based on the determination.

10 . The system of claim 8 , wherein the executing further comprises:

performing a selectivity comparison between the one or more second constants of the previously received query and the one or more first constants of the query;

determining that a first selectivity of the one or more first constants of the query fall outside a range of a second selectivity of the one or more second constants of the previously received query;

recompiling the matching execution plan in view of the determination; and

executing the recompiled matching execution plan.

11 . The system of claim 8 , wherein the comparing comprises:

comparing a first table of the normalized query to a second table of the matching query to determine that the first table is identical to the second table.

12 . The system of claim 11 , the operations further comprising:

comparing one or more first fields of the normalized query to one or more second fields of the matching query to determine that the one or more first fields are identical to the one or more second fields.

13 . The system of claim 8 , wherein the performing normalization comprises:

identifying an OR statement between a first value and a second value in the query;

removing the OR statement; and

replacing the first value and the second value with the variable-indicator.

14 . The system of claim 8 , wherein the performing normalization comprises:

identifying an AND statement between a first field and a second field in the query; and

sorting the first field and the second field alphabetically.

15 . A non-transitory computer-readable medium having instructions stored thereon that, when executed by at least one computing device, cause the at least one computing device to perform operations comprising:

receiving a query on a database, the query comprising one or more first constants;

performing normalization on the query to generate a normalized query, the normalization comprising replacing the one or more first constants with a variable-indicator;

comparing the normalized query to one or more previously generated normalized queries to identify a matching query of the one or more previously generated normalized queries, wherein the matching query corresponds to a previously received query comprising one or more second constants;

selecting a matching execution plan of one or more previously saved execution plans, based on the matching execution plan corresponding to the matching query, wherein each of the one or more previously saved execution plans is pre-compiled;

executing the matching execution plan, for the query, on the database, wherein the executing comprises providing the one or more first constants as runtime variables;

generating a result from the execution of the matching execution plan; and

returning the result as a result of the query.

16 . The non-transitory computer-readable medium of claim 15 ,

wherein the executing further comprises:

performing a selectivity comparison between the one or more second constants of the previously received query and the one or more first constants of the query;

determining that a first selectivity of the one or more first constants of the query fall within a range of a second selectivity of the one or more second constants of the previously received query; and

selecting the matching execution plan based on the determination.

17 . The non-transitory computer-readable medium of claim 15 ,

wherein the executing further comprises:

performing a selectivity comparison between the one or more second constants of the previously received query and the one or more first constants of the query;

determining that a first selectivity of the one or more first constants of the query fall outside a range of a second selectivity of the one or more second constants of the previously received query;

recompiling the matching execution plan in view of the determination; and

executing the recompiled matching execution plan.

18 . The non-transitory computer-readable medium of claim 15 , wherein the comparing comprises:

comparing a first table of the normalized query to a second table of the matching query to determine that the first table is identical to the second table.

19 . The non-transitory computer-readable medium of claim 18 , the operations further comprising:

comparing one or more first fields of the normalized query to one or more second fields of the matching query to determine that the one or more first fields are identical to the one or more second fields.

20 . The non-transitory computer-readable medium of claim 15 , wherein the performing normalization comprises:

identifying an OR statement between a first value and a second value in the query;

removing the OR statement; and

replacing the first value and the second value with the variable-indicator.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jun 26, 2024
From: BENSBERG, CHRISTIAN; MERX, JOHANNES
To: SAP SE
Reel/Frame 067843/0549 →
Continuity (1)
Related Publication 20250384034A1 · Dec 18, 2025
References Cited (8)
US 11314740B1 · Hwang · 2022 [cited by examiner]
US 12229642B2 · Dirac · 2025 [cited by examiner]
US 12248484B2 · Pal · 2025 [cited by examiner]
US 20080086444A1 · Yu · 2008 [cited by examiner]
US 20130247207A1 · Hugard, IV · 2013 [cited by examiner]
US 20200050607A1 · Pal · 2020 [cited by examiner]
US 20210191942A1 · Arnold · 2021 [cited by examiner]
US 20220245148A1 · Hwang · 2022 [cited by examiner]