# US 2021/0240710 A1 · Query plan overrides

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2021/0240710 A1
- Document ID: US20210240710A1
- Status: Published application
- Kind: A1
- Application number: 16/778,938
- Filed: 2020-01-31
- Published: 2021-08-05
- Earliest claimed: 2020-01-31
- Assignees: salesforce.com, inc.
- Applicants: salesforce.com, inc.
- Inventors: Rama Krishna Korlapati; William J. McKenna; John Francis O'Brien
- Web page: https://patentgrep.com/patent/US20210240710A1

## CPC

- G06F 16/24537: {of operators}
- G06F 16/24544: {Join order optimisation}
- G06F 11/3409: {for performance assessment}
- G06F 11/3476: {Data logging (G06F11/14, G06F11/2205 take precedence)}
- G06F 16/24526: {Internal representations for queries}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Techniques are disclosed relating to database query optimizers. In some embodiments, a query parser of a database system receives a query requesting data from a multi-tenant database. The query includes a first constraint that restricts a query optimizer's selection of a set of execution plans available to implement the query. The database system determines whether an override has been specified for a particular tenant associated with the received query, the override indicating that the first constraint is to be replaced with a second constraint for the particular tenant. In response to determining that the override has been specified for the particular tenant, the database system replaces the first constraint in the query with the second constraint and provides the query with the second constraint to the query optimizer for selection of an execution plan in accordance with the second constraint.

## Claims

### Claim 1

A non-transitory computer readable medium having program instructions stored thereon that are capable of causing a computer system to implement operations comprising:
receiving, at a query parser of a database system, a query requesting data from a multi-tenant database, wherein the query includes a first constraint that restricts a query optimizer's selection of a set of execution plans available to implement the query;
determining, by the database system, whether an override has been specified for a particular tenant associated with the query, wherein the override indicates that the first constraint is to be replaced with a second constraint for the particular tenant;
in response to determining that the override has been specified for the particular tenant:
replacing, by the database system, the first constraint with the second constraint; and
providing, by the database system, the query with the second constraint to the query optimizer for selection of an execution plan in accordance with the second constraint.

### Claim 2 (depends on 1)

The computer readable medium of claim 1, wherein the query is received from an application; and
wherein the replacing does not modify the query as specified in one or more program instructions of the application.

### Claim 3 (depends on 1)

The computer readable medium of claim 1, wherein the first constraint identifies a first index to be used in performing the query; and
wherein the second constraint identifies a second index to be used instead of the first index in performing the query.

### Claim 4 (depends on 1)

The computer readable medium of claim 1, wherein the first constraint indicates that a join specified in the query is to be performed using a first physical join operation; and
wherein the second constraint indicates that the join specified in the query is to be performed using a second physical join operation instead of the first physical join operation.

### Claim 5 (depends on 1)

The computer readable medium of claim 1, wherein determining whether the override has been specified for the particular tenant includes:
accessing a catalog of the multi-tenant database to determine whether the catalog includes the override.

### Claim 6 (depends on 5)

The computer readable medium of claim 5, wherein the operations further comprise:
receiving, with the query, a first identifier of the particular tenant associated with the received query; and
wherein the accessing includes using the first identifier to query a table in the catalog to determine whether the override has been specified for the particular tenant.

### Claim 7 (depends on 6)

The computer readable medium of claim 6, wherein the operations further comprise:
receiving, with the query, a second identifier indicating a particular user of the particular tenant; and
wherein the accessing includes using the second identifier to query the table in the catalog to determine whether the override has been specified for the particular user.

### Claim 8 (depends on 5)

The computer readable medium of claim 5, wherein accessing the catalog includes reading expiration criteria for the override from the catalog; and
wherein the determining includes determining, based on the expiration criteria, whether the override has expired.

### Claim 9 (depends on 5)

The computer readable medium of claim 5, wherein the operations further comprise:
receiving a location identifier indicating a location of the first constraint within the query; and
accessing a table in the catalog to determine whether the override has been specified for the location indicated by the location identifier.

### Claim 10 (depends on 1)

The computer readable medium of claim 1, wherein the operations further comprise:
in response to the query optimizer selecting the execution plan in accordance with the second constraint, storing the selected execution plan in a cache of the database system for servicing a subsequently received instance of the query associated with the particular tenant.

### Claim 11

A method, comprising:
sending, by an application, a query requesting data for a particular tenant from a multi-tenant database, wherein the query includes a first constraint to restrict a query optimizer's selection of a set of execution plans available to implement the query; and
receiving, by the application, query results for the query, wherein the query results are determined using an execution plan selected by the query optimizer based on a second constraint identified in an override for the particular tenant, wherein the override indicates that that the first constraint is to be replaced with the second constraint when servicing the query for the particular tenant.

### Claim 12 (depends on 11)

The method of claim 11, wherein the first constraint specifies a first ordering for joining content from a plurality of tables in the multi-tenant database, and wherein the second constraint specifies a second ordering for joining content from the plurality of tables in the multi-tenant database.

### Claim 13 (depends on 11)

The method of claim 11, wherein the query is parsed by a query parser that, based on the override, replaces the first constraint with the second constraint.

### Claim 14 (depends on 13)

The method of claim 13, wherein the query parser accesses a catalog of the multi-tenant database to determine whether the override has been specified for the particular tenant.

### Claim 15 (depends on 14)

The method of claim 14, further comprising:
sending, by the application, an indication of a current user associated with the query, wherein the indication is usable by the query parser to determine that the override has been specified for the current user.

### Claim 16

A computer system, comprising:
one or more processors;
memory having program instructions stored therein that are executable by the one or more processors to implement a database system performing operations including:
receiving a request to perform a query for a particular tenant of a multi-tenant database, wherein the request includes a first constraint to restrict a query optimizer's selection of execution plans available to implement the query;
determining that an override has been specified for the particular tenant, wherein the override indicates that the first constraint is to be replaced with a second constraint;
in response to the determining, the query optimizer selecting an execution plan based on the second constraint and not based on the first constraint; and
executing the selected execution plan to perform the query.

### Claim 17 (depends on 16)

The computer system of claim 16, wherein the operations further comprise:
replacing, by a query parser, the first constraint with the second constraint; and
providing, by the query parser, the second constraint to the query optimizer to facilitate selecting the execution plan.

### Claim 18 (depends on 16)

The computer system of claim 16, wherein the determining includes:
accessing a table in a database catalog of the multi-tenant database, wherein the table is operable to store one or more overrides for tenants of the multi-tenant database.

### Claim 19 (depends on 16)

The computer system of claim 16, wherein the determining includes:
determining whether the override has expired based on expiration criteria stored for the override.

### Claim 20 (depends on 16)

The computer system of claim 16, wherein the operations further comprise:
storing, in a cache, the selected execution plan to facilitate a subsequent performance of the query for the particular tenant; and
storing, in the cache, another execution plan selected by the query optimizer based on the first constraint to facilitate a subsequent performance of the query for a tenant other than the particular tenant.
