Query hint specification
AssigneeAmazon Technologies, Inc.
InventorsNeil Thombre, Zelaine Fong, Stefano Stefani, Hakan Jakobsson, Anurag Windlass Gupta
Life of this patent
Estimating the term…
Abstract
A query optimizer may receive a query block that includes a hint. The hint may include a unique object identifier to specify an object to which the hint applies. In some instances, the object may correspond to a nested query block. A query optimization plan may be determined based, at least in part, on the hint. The query execution plan may then be executed to query a data store.
Claims15
A system, comprising:
- a memory;
- one or more processors coupled to the memory, wherein the memory comprises program instructions executable by the one or more processors to:
- receive, by a parser, a query to a database, wherein the query specifies a hint and a query block, wherein the hint is usable to optimize the query, wherein the hint includes a unique object identifier uniquely specifying an object recited within the query block to which the hint applies, wherein the unique object identifier corresponds to a nested query block of the query block, and wherein the unique object identifier is relative to the query block;
- determine, by an optimizer, a location of the specified object within the query block to which the hint applies according to an interpretation of the unique object identifier with respect to locations within the query block to locate the specified object in the query block, wherein the unique object identifier is specified from an unambiguous numbering scheme, the unambiguous numbering scheme corresponding to a specific scope of the query block in which objects are numbered sequentially inside the query block in an order of appearance to the parser;
- obtain, by the optimizer, a local reference of the unique object identifier by truncating a prefix of the unique object identifier, wherein the truncated prefix is an identifier of the query block;
- rewrite, by the optimizer, the query by inserting the hint at a top level of the determined query block location and replacing the unique object identifier in the hint with the local reference of the unique object identifier;
- select, by the optimizer, a query execution plan to optimize the rewritten query based, at least in part, on the application of the hint to the specified object;
- and
- execute, by a compute node, the query execution plan to perform the query to the database.
A method, comprising:
- performing, by one or more computers:
- receiving a query that specifies a hint and a query block, wherein the hint is usable to optimize the query, wherein the hint includes a unique object identifier uniquely specifying an object recited within the query block to which the hint applies, wherein the unique object identifier corresponds to a nested query block of the query block, and wherein the unique object identifier is relative to the query block;
- determining a location of the specified object within the query block to which the hint applies according to an interpretation of the unique object identifier with respect to locations within the query block to locate the specified object in the query block, wherein the unique object identifier is specified from an unambiguous numbering scheme, the unambiguous numbering scheme corresponding to a specific scope of the query block in which objects are numbered sequentially inside the query block in an order of appearance to a parser;
- obtain, by the optimizer, a local reference of the unique object identifier by truncating a prefix of the unique object identifier, wherein the truncated prefix is an identifier of the query block;
- rewriting the query by inserting the hint at a top level of the determined query block location and replacing the unique object identifier in the hint with the local reference of the unique object identifier;
- selecting a query execution plan to optimize the rewritten query based, at least in part, on the application of the hint to the specified object;
- and
- executing the query execution plan to perform the query to a data store.
A non-transitory computer-readable storage medium storing program instructions, wherein the program instructions are computer-executable to implement:
- receiving a query that specifies a hint and a query block, wherein the hint is usable to optimize the query, wherein the hint includes a unique object identifier uniquely specifying an object recited within the query block to which the hint applies, wherein the unique object identifier corresponds to a subquery block of the query block, and wherein the unique object identifier is relative to the query block;
- determining a location of the specified object within the query block to which the hint applies according to an interpretation of the unique object identifier with respect to locations within the query block to locate the specified object in the query block, wherein the unique object identifier is specified from an unambiguous numbering scheme, the unambiguous numbering scheme corresponding to a specific scope of the query block in which objects are numbered sequentially inside the query block in an order of appearance to a parser;
- obtaining a local reference of the unique object identifier by truncating a prefix of the unique object identifier, wherein the truncated prefix is an identifier of the query block;
- rewriting the query by inserting the hint at a top level of the determined query block location and replacing the unique object identifier in the hint with the local reference of the unique object identifier;
- selecting a query execution plan to optimize the rewritten query based, at least in part, on the application of the hint to the specified object;
- and
- executing the query execution plan to perform the query to a database.
Dependencies are inferred from the claim text.