# US 2021/0286795 A1 · Database index and database query processing method, apparatus, and device

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

- Number: US 2021/0286795 A1
- Document ID: US20210286795A1
- Status: Published application
- Kind: A1
- Application number: 17/332,724
- Filed: 2021-05-27
- Published: 2021-09-16
- Earliest claimed: 2018-11-27
- Assignees: Alibaba Group Holding Limited
- Applicants: Alibaba Group Holding Limited
- Inventors: Wei HU; Jie Zhou; Dengcheng HE
- Web page: https://patentgrep.com/patent/US20210286795A1

## CPC

- G06F 16/2246: {Trees, e.g. B+trees}
- G06F 11/3409: {for performance assessment}
- G06F 16/2282: {Tablespace storage structures; Management thereof}
- G06F 16/2453: Query optimisation
- G06F 16/9537: Spatial or temporal dependent retrieval, e.g. spatiotemporal queries
- Y02D 10/00: Energy efficient computing, e.g. low power processors, power management or thermal management
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- Y02D: CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE

## Abstract

A method including determining a database table for which a database index is to be created, wherein the database table comprises a spatial field for storing spatial data; acquiring, for the database table, a spatial filter condition comprising a spatial field ID; and generating, according to the spatial filter condition, a tree-structured spatial index for the database table, wherein a leaf node of the tree-structured spatial index stores therein spatial data meeting the spatial filter condition and its primary key ID. The efficiency of queries related to spatial data is thus enhanced.

## Claims

### Claim 1

A method comprising:
determining a database table for which a database index is to be created, the database table comprising a spatial field for storing spatial data;
acquiring, for the database table, a spatial filter condition comprising a spatial field ID; and
generating, according to the spatial filter condition, a tree-structured spatial index for the database table, a leaf node of the tree-structured spatial index storing therein spatial data meeting the spatial filter condition and a primary key ID.

### Claim 2 (depends on 1)

The method according to claim 1, wherein:
the spatial filter condition comprises spatial field prefix information; and
the generating, according to the spatial filter condition, the tree-structured spatial index for the database table comprises:
acquiring, according to the spatial filter condition, spatial field prefix information used for generating the tree-structured spatial index;
generating, according to the spatial field prefix information, a spatial prefix index for the database table, an index column of the spatial prefix index comprising the spatial field prefix information; and
using the spatial prefix index as the tree-structured spatial index.

### Claim 3 (depends on 2)

The method according to claim 2, wherein:
the spatial filter condition comprises a filter condition of a minimum bounding rectangle operation type; and
the generating, according to the spatial field prefix information, the spatial prefix index for the database table comprises:
performing, according to the filter condition of the minimum bounding rectangle operation type, a minimum bounding box filtering on the database table to obtain an alternative spatial field meeting the filter condition of the minimum bounding rectangle operation type;
performing a standard byte-stream encoding for geospatial information on spatial data stored in the alternative spatial field; and
generating the spatial prefix index of the database table according to the spatial data on which the standard byte-stream encoding for geospatial information is performed and the spatial field prefix information.

### Claim 4 (depends on 3)

The method according to claim 3, wherein:
the spatial field prefix information comprises a condition for indicating a length of spatial data stored in the spatial field; and
the generating the spatial prefix index of the database table according to the spatial data on which the standard byte-stream encoding for geospatial information is performed and the spatial field prefix information comprises:
acquiring a length of the spatial data on which the standard byte-stream encoding for geospatial information is performed;
acquiring a length condition according to the spatial field prefix information; and
in response to determining that the length of the spatial data on which the standard byte-stream encoding for geospatial information is performed meets the length condition, storing in a leaf node of the spatial prefix index the spatial data meeting the length condition; or
in response to determining that the length of the spatial data on which the standard byte-stream encoding for geospatial information is not performed meets the length condition, determining not to store in the leaf node of the spatial prefix index the spatial data.

### Claim 5 (depends on 1)

The method according to claim 1, wherein the generating, according to the spatial filter condition, the tree-structured spatial index for the database table comprises:
acquiring, according to the spatial filter condition, information of a spatial field used for generating the tree-structured spatial index;
acquiring information of a non-spatial field used for generating the tree-structured spatial index;
generating, according to the information of the spatial field and the information of the non-spatial field, a composite spatial index of the database table, an index column of the spatial composite index comprising the spatial field and the non-spatial field; and
using the composite spatial index as the tree-structured spatial index.

### Claim 6 (depends on 1)

The method according to claim 1, wherein the generating, according to the spatial filter condition, the tree-structured spatial index for the database table comprises:
acquiring, according to the spatial filter condition, information of a spatial field prefix used for generating the tree-structured spatial index;
acquiring information of a non-spatial field used for generating the tree-structured spatial index;
generating, according to the information of the spatial field prefix and the information of the non-spatial field, a composite prefix spatial index, an index column of the composite prefix spatial index comprising the spatial field prefix and the non-spatial field; and
using the spatial composite prefix index as the tree-structured spatial index.

### Claim 7 (depends on 1)

The method according to claim 1, wherein:
an index column of the tree-structured spatial index comprises a spatial field; and
a non-leaf node of the tree-structured spatial index stores therein a minimum bounding rectangle for retrieving the spatial data and a page ID for searching a next-level page.

### Claim 8 (depends on 1)

The method according to claim 1, further comprising:
creating, according to a database table creation command, the database table, the database table creation command comprising an index creation command for generating the tree-structured spatial index; or
creating, according to the index creation command, the tree-structured spatial index.

### Claim 9

A method comprising:
determining a database table within which spatial data is to be queried, the database table comprising a spatial field for storing spatial data;
acquiring, for the database table, a query condition comprising a spatial query field;
acquiring a tree-structured spatial index of the database table, a leaf node of the tree-structured spatial index storing therein spatial data; and
querying, according to the query condition, the tree-structured spatial index to obtain a query result.

### Claim 10 (depends on 9)

The method according to claim 9, wherein:
the query condition further comprises a non-spatial field; and
the querying, according to the query condition, the tree-structured spatial index to obtain the query result comprises:
acquiring a spatial field of the query condition;
determining whether the spatial field matches a spatial field ID of an index column of the tree-structured spatial index; and
in response to determining that the spatial field matches a spatial field ID of an index column of the tree-structured spatial index, querying, according to the spatial query field of the query condition, a composite spatial index of the database table to obtain a query result meeting the query condition; or
in response to determining that the spatial field does not match a spatial field ID of an index column of the tree-structured spatial index, obtaining an alternative record of a non-spatial query field matching the query condition in the database table, and acquiring, according to the spatial query field of the query condition and from the alternative record, a query result meeting the query condition.

### Claim 11 (depends on 10)

The method according to claim 10, wherein the querying, according to the spatial query field of the query condition, the composite spatial index of the database table to obtain the query result meeting the query condition comprises:
acquiring a non-spatial query field of the query condition;
determining that the spatial query field and the non-spatial query field are at in index column comprised in the composite spatial index of the database table; and
determining that the query condition meets a spatial index query mode of the database table, and querying, according to the query condition, the composite spatial index of the database table using a covering index scan.

### Claim 12 (depends on 10)

The method according to claim 10, wherein the querying, according to the spatial query field of the query condition, the composite spatial index of the database table to obtain the query result meeting the query condition comprises:
acquiring a non-spatial query field of the query condition;
determining that the spatial query field and the non-spatial query field are not at in index column comprised in the composite spatial index of the database table; and
querying to find, according to the query condition, an alternative record meeting the query condition from the composite spatial index of the database table, and according to a primary key of the alternative record, returning to the database table for further querying and obtaining a complete row record that meets the query condition.

### Claim 13 (depends on 11)

The method according to claim 11, wherein the querying, according to the query condition, the composite spatial index of the database table using the covering index scan comprises:
determining, according to the spatial query field, that the spatial query field is a spatial field of the composite spatial index of the database table that is queried; and
querying the composite spatial index using the covering index scan according to a length condition included in prefix information of the spatial query field.

### Claim 14 (depends on 11)

The method according to claim 11, wherein the querying, according to the query condition, the composite spatial index of the database table using the covering index scan comprises:
determining, according to the spatial query field, that the spatial query field is not a spatial field of the composite spatial index of the database table that is queried; and
querying the composite spatial index of the database table using the covering index scan.

### Claim 15 (depends on 14)

The method according to claim 14, wherein the querying the composite spatial index using the covering index scan according to the length condition included in prefix information of the spatial query field comprises:
acquiring the length condition included in the prefix information of the spatial query field;
determining whether a length of a row record of the composite spatial index meets the length condition; and
in response to determining that the length of the row record of the composite spatial index meets the length condition, using the row record as a query result of the covering index scan; and
in response to determining that the length of the row record of the composite spatial index does not meet the length condition, querying the database table according to primary key information.

### Claim 16 (depends on 10)

The method according to claim 10, wherein the acquiring, according to the spatial query field of the query condition and from the alternative record, the query result meeting the query condition comprises:
performing a spatial computation on data of the alternative row record, and, according to a computation result, acquiring, from the alternative row record, a row record that accords with the spatial query field; and
using the row record that accords with the spatial query field as the query result meeting the query condition.

### Claim 17 (depends on 9)

The method according to claim 9, wherein spatial query information of the query condition is a minimum bounding rectangle operation comprising the spatial query field.

### Claim 18 (depends on 9)

The method according to claim 9, wherein:
an index column of the tree-structured spatial index comprises the spatial field.

### Claim 19 (depends on 9)

The method according to claim 9, wherein:
a non-leaf node of the tree-structured spatial index stores therein a minimum bounding rectangle for retrieving the spatial data and a page ID for searching a next-level page.

### Claim 20

An apparatus comprising:
one or more processors; and
one or more computer readable media storing thereon computer-readable instructions that, when executed by the one or more processors, cause the one or more processors to perform acts comprising:
determining a database table for which a database index is to be created, the database table comprising a spatial field for storing spatial data;
acquiring, for the database table, a spatial filter condition comprising a spatial field ID; and
generating, according to the spatial filter condition, a tree-structured spatial index for the database table, wherein a leaf node of the tree-structured spatial index stores therein spatial data meeting the spatial filter condition and a primary key ID.
