DATABASE INDEX AND DATABASE QUERY PROCESSING METHOD, APPARATUS, AND DEVICE - Patent application
The implementation of a tree-structured spatial index in databases that stores spatial data at its leaf nodes addresses inefficiencies in spatial data queries by enabling direct result retrieval, thereby improving query efficiency and reducing overhead.
Patent Information
- Application Number
- JP2021529833
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2018-11-27
- Filing Date
- 2019-11-19
- Publication Date
- 2024-08-26
- Estimated Expiration
- 2039-11-19
AI Technical Summary
Existing spatial data queries in databases are inefficient due to the need for significant CPU and IO overhead when filtering spatial data, as current spatial indexing only stores minimum bounding rectangle information, requiring additional table accesses to retrieve complete records.
A tree-structured spatial index is generated that stores spatial data satisfying filter conditions at its leaf nodes, allowing direct retrieval of query results without additional table accesses, and can include composite indexes for non-spatial fields to further reduce overhead.
This approach enhances spatial data query efficiency by reducing the need for table accesses and improving query performance, especially when large numbers of records match spatial filter conditions.
Smart Images

Figure 0007539884000002 
Figure 0007539884000003 
Figure 0007539884000001
Abstract
Description
[Technical field]
[0001] This application claims priority to Chinese Patent Application No. 2018 / 11422523.X, entitled “DATABASE INDEX AND DATABASE QUERY PROCESSING METHOD, APPARATUS, AND DEVICE”, filed on November 27, 2018, the entire contents of which are incorporated herein by reference.
[0002] This application relates to the field of data processing, and more particularly to methods, apparatus, electronic devices, and storage devices for processing database indexes. This application also relates to methods, apparatus, electronic devices, and storage devices for processing database queries. [Background technology]
[0003] With the development of computers and information technology, spatial data and databases supporting the storage and management of spatial data are widely used in various industries such as urban planning, transportation, banking, and aerospace. So-called spatial data, also known as geometric data, is a special form of data that can be processed by a computer to display information including spatial coordinates. Examples of such data include spatial data representing architectural blueprints, mechanical blueprints, and maps. Spatial data can quantitatively describe the occurrence of objects and events that have positioning significance in the real world, such as identifying the location, shape, size, and distribution characteristics of spatial entities. So-called spatial entities are the result of abstracting the occurrence of geographical objects and things, and are also called geographical entities or entities.
[0004] Currently, databases supporting storage and management of spatial data generally provide spatial indexing for fast reading and integrity checking of the spatial data stored therein. The so-called spatial indexing is a data structure arranged in a specific order according to the location and shape of spatial objects or the specific spatial relationships between spatial objects. Existing spatial indexing only stores information that may cover the minimum bounding rectangle (MBR) of a spatial object. The so-called MBR refers to the minimum bounding rectangle that covers a spatial object in two dimensions. When spatial data is queried, the spatial data that meets the spatial filter condition is first filtered and selected. Then, it is necessary to return to the primary key table for further filtering to obtain the complete record. Therefore, when the number of records that match the spatial filter condition during a query is relatively large, the CPU and IO overhead for returning to the primary key table to obtain the complete record is relatively large, resulting in a relatively low efficiency of the spatial data query. Summary of the Invention [Means for solving the problem]
[0005] The present application provides a database indexing method and a database query processing method to improve the efficiency of queries on spatial data.
[0006] The present application provides a database indexing method, the method comprising: determining a database table for which a database index is to be created, the database table including a spatial field for storing spatial data; Obtaining a spatial filter condition for a database table, the spatial filter condition including a spatial field ID; generating a tree-structured spatial index for the database table according to the spatial filter condition, where leaf nodes of the tree-structured spatial index store spatial data that satisfies the spatial filter condition and a primary key ID;
[0007] Optionally, the spatial filter condition includes spatial field prefix information; Generating a tree-structured spatial index for a database table according to a spatial filter condition Obtaining spatial field prefix information used to generate a tree-structured spatial index according to a spatial filter condition; generating a spatial prefix index for the database table according to the spatial field prefix information, where an index column of the spatial prefix index includes the spatial field prefix information; and using a spatial prefix index as the tree-structured spatial index.
[0008] Optionally, the spatial filter condition comprises a minimum bounding rectangle operation type filter condition; Generating spatial prefix indexes for database tables according to spatial field prefix information performing minimum bounding rectangle filtering on the database table according to the minimum bounding rectangle operation type filter condition to obtain an alternative spatial field that satisfies the minimum bounding rectangle operation type filter condition; performing a standard byte stream encoding for geospatial information on the spatial data stored in the alternative spatial field; generating a spatial prefix index for the database table according to the spatial data on which standard byte stream encoding for geospatial information has been performed and the spatial field prefix information;
[0009] Optionally, the spatial field prefix information includes a term to indicate a length of the spatial data stored in the spatial field; generating a spatial prefix index for a database table according to spatial data that has been subjected to standard byte stream encoding for geospatial information and spatial field prefix information; Obtaining a length of spatial data on which a standard byte stream encoding for geospatial information has been performed; Obtaining a length condition according to the spatial field prefix information; If the length of the spatial data on which standard byte stream encoding for geospatial information has been performed satisfies the length condition, storing the spatial data that satisfies the length condition in a leaf node of the spatial prefix index; Otherwise, the leaf nodes of a spatial prefix index do not store any spatial data.
[0010] Optionally, generating a tree-structured spatial index for the database table according to the spatial filter condition includes: obtaining information of a spatial field used to generate a tree-structured spatial index according to a spatial filter condition; Obtaining information about non-spatial fields used to generate a tree-structured spatial index; generating a composite spatial index for the database table according to information of the spatial field and information of the non-spatial field, where an index column of the spatial composite index includes the spatial field and the non-spatial field; and using the composite spatial index as a tree-structured spatial index.
[0011] Optionally, generating a tree-structured spatial index for the database table according to the spatial filter condition includes: Obtaining spatial field prefix information used to generate a tree-structured spatial index according to a spatial filter condition; Obtaining information about non-spatial fields used to generate a tree-structured spatial index; generating a composite prefix spatial index according to information of the spatial field prefix and information of the non-spatial field, where an index column of the composite prefix spatial index includes the spatial field prefix and the non-spatial field; and using a spatial compound prefix index as the tree-structured spatial index.
[0012] Optionally, index columns of the tree-structured spatial index include a spatial field, and non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving spatial data and a page ID for searching the next level page.
[0013] Optionally, the method further comprises: creating a database table according to database table creation commands, the database table creation commands including an index creation command for generating a tree-structured spatial index; or It further includes creating a tree-structured spatial index according to the index creation command.
[0014] The present application further provides a database query processing method, the method comprising: determining a database table from which the spatial data is queried, the database table including a spatial field for storing the spatial data; obtaining a query condition for a database table, the query condition including a spatial query field; Obtaining a tree-structured spatial index for a database table, the leaf nodes of the tree-structured spatial index storing spatial data; Querying the tree-structured spatial index according to the query condition to obtain a query result.
[0015] Optionally, the query condition further comprises a non-spatial field; Querying a tree-structured spatial index according to a query condition to obtain a query result is Obtaining the spatial fields of the query criteria; and determining whether the spatial field matches a spatial field ID of an index column of the tree-structured spatial index; if so, querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain a query result that satisfies the query condition; If not, obtaining an alternative record for the non-spatial query field that matches the query condition in the database table, and obtaining query results that satisfy the query condition according to the spatial query field of the query condition and from the alternative record.
[0016] Optionally, querying a composite spatial index of a database table according to a spatial query field of a query condition to obtain a query result that satisfies the query condition; Obtaining a non-spatial query field of the query condition; determining whether the spatial query field and the non-spatial query field are index columns included in a composite spatial index for the database table; if so, determining that the query condition satisfies a spatial index query mode of the database table, and querying the composite spatial index of the database table using a covering index scan according to the query condition; If not, querying from the composite spatial index of the database table according to the query condition to find an alternate record that satisfies the query condition, and further querying back to the database table according to the primary key of the alternate record to obtain a complete row record that satisfies the query condition.
[0017] Optionally, querying a composite spatial index on a database table using a covering index scan according to a query condition; Determining whether the spatial query field is a spatial field of a composite spatial index of the queried database table according to the spatial query field; if so, querying the composite spatial index using a covering index scan according to the length condition contained in the prefix information of the spatial query field; If not, querying the composite spatial index of the database table using a covering index scan.
[0018] Optionally, querying a composite spatial index using a covering index scan according to length conditions contained in prefix information of the spatial query field; Obtaining a length condition included in prefix information of a spatial query field; determining whether a length of a row record of the composite spatial index satisfies a length condition, and if so, using the row record as a query result of a covering index scan; If not, querying the database table according to the primary key information.
[0019] Optionally, obtaining query results that satisfy the query condition according to a spatial query field of the query condition and from the alternative record includes: performing spatial calculations on the data of the alternate row records and retrieving row records from the alternate row records that match the spatial query field according to the calculation results; Using the row records that satisfy the spatial query field as query results that satisfy the query condition.
[0020] Optionally, the spatial query information of the query condition is a minimum bounding rectangle operation that includes the spatial query field.
[0021] Optionally, index columns of the tree-structured spatial index include a spatial field, and non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving spatial data and a page ID for searching the next level page.
[0022] The present application further provides a database index processing device, the device comprising: a database table determining unit configured to determine a database table on which a database index is to be created, the database table including a spatial field for storing spatial data; a filter condition obtaining unit configured to obtain a spatial filter condition including a spatial field ID for the database table; The index generation unit is configured to generate a tree-structured spatial index for a database table according to a spatial filter condition, wherein a leaf node of the tree-structured spatial index stores spatial data that satisfies the spatial filter condition and a primary key ID.
[0023] The present application further provides a database query processing apparatus, the apparatus comprising: a database table determining unit configured to determine a database table to which the spatial data is queried, the database table including a spatial field for storing the spatial data; a query condition determination unit configured to obtain a query condition for the database table, the query condition including the spatial query field; an indexing unit configured to obtain a tree-structured spatial index for a database table, the leaf nodes of the tree-structured spatial index storing spatial data; a query unit configured to query the tree-structured spatial index according to a query condition to obtain a query result.
[0024] This application is There is further provided an electronic device comprising a memory and a processor, The memory is configured to store computer-executable instructions, and the processor is determining a database table for which a database index is to be created, the database table including a spatial field for storing spatial data; Obtaining a spatial filter condition for a database table, the spatial filter condition including a spatial field ID; The method is configured to execute the following computer-executable commands: generate a tree-structured spatial index for the database table according to the spatial filter condition, wherein leaf nodes of the tree-structured spatial index store spatial data that satisfies the spatial filter condition and a primary key ID.
[0025] This application is There is further provided an electronic device comprising a memory and a processor, The memory is configured to store computer-executable instructions, and the processor is determining a database table from which the spatial data is queried, the database table including a spatial field for storing the spatial data; obtaining a query condition for a database table, the query condition including a spatial query field; Obtaining a tree-structured spatial index for a database table, the leaf nodes of the tree-structured spatial index storing spatial data; The method is configured to execute computer-executable commands of: querying the tree-structured spatial index according to the query condition to obtain a query result.
[0026] The present application further provides a storage device having stored commands, the commands comprising: determining a database table for which a database index is to be created, the database table including a spatial field for storing spatial data; obtaining a spatial filter condition for a database table, the spatial filter condition including a spatial field ID; The method may be loaded by a processor to execute the steps of: generating a tree-structured spatial index for the database table according to a spatial filter condition, wherein leaf nodes of the tree-structured spatial index store spatial data that satisfies the spatial filter condition, and a primary key ID.
[0027] The present application further provides a storage device having stored commands, the commands comprising: determining a database table from which the spatial data is to be queried, the database table including a spatial field for storing the spatial data; obtaining a query condition for a database table, the query condition including a spatial query field; obtaining a tree-structured spatial index for a database table, the leaf nodes of the tree-structured spatial index storing spatial data; and querying the tree-structured spatial index according to a query condition to obtain a query result.
[0028] Compared with the prior art, the present application has the following advantages: The database index processing method provided by the present application generates a tree-structured spatial index for a database table according to a spatial filter condition of the database table including a spatial field, and stores the spatial data that meets the spatial filter condition in a leaf node of the tree-structured spatial index. By storing the spatial data in the index, the query efficiency of the spatial data is improved, thereby solving the problem of low query efficiency of the spatial data. Furthermore, if the tree-structured spatial index is a composite spatial index including a non-spatial field, filtering of the non-spatial column can be further provided, thereby reducing the number of table accesses by index rowid calculation and improving query efficiency.
[0029] According to a query condition including a spatial query field, the database query processing method provided by the present application queries a tree-structured spatial index of a database table to obtain a query result. Because the leaf nodes of the tree-structured spatial index store spatial data, the overhead for querying spatial data is reduced, thereby solving the problem of low query efficiency of spatial data. Furthermore, if the tree-structured spatial index is a composite spatial index including non-spatial fields, filtering of non-spatial columns can be further provided, thereby reducing the number of table accesses by index rowid calculations and improving query efficiency. [Brief description of the drawings]
[0030] [Figure 1] 2 is a processing flowchart of a database index processing method according to the first embodiment of the present application. [Diagram 2] FIG. 2 is a schematic structural diagram of a database index according to the first embodiment of the present application. [Diagram 3] 11 is a processing flowchart of a database query processing method according to a second embodiment of the present application. [Figure 4] 11 is a flowchart of an actual implementation of a database query according to a second embodiment of the present application; [Diagram 5] FIG. 11 is a schematic diagram of a database index processing device according to a third embodiment of the present application. [Figure 6] FIG. 11 is a schematic diagram of a database query processing device according to a fourth embodiment of the present application. [Figure 7] FIG. 11 is a schematic diagram of an electronic device according to a fifth embodiment of the present application. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0031] In the following description, many specific details are described to enable those skilled in the art to fully understand the present application. However, the present application can be implemented in many other ways different from those described herein. Those skilled in the art can make similar generalizations without departing from the spirit of the present application. Therefore, the present application is not limited by the specific implementations disclosed below.
[0032] The present application provides a method, an apparatus, an electronic device, and a storage device for processing a database index. The present application also relates to a method, an apparatus, an electronic device, and a storage device for processing a database query. In each of the following embodiments, a detailed description is provided.
[0033] A first embodiment of the present application provides a database index processing method.
[0034] The database indexing method provided by the embodiment of the present application is described below in conjunction with FIG. 1 and FIG.
[0035] The database index processing method shown in FIG. 1 includes steps S101 to S103.
[0036] Step S101: Determine a database table for which a database index is to be created, and the database table includes a spatial field for storing spatial data.
[0037] In practical applications, databases that support spatial data usually provide spatial indexing. Conventional spatial indexing only stores MBR and / or minimum bounding box (MBB) information, so further table access by index rowid operation is required. The so-called MBB and MBR refer to the smallest bounding extent that encompasses a spatial object. The smallest bounding extent that encompasses a spatial object in two dimensions is the minimum bounding rectangle (MBR), and the smallest bounding extent that encompasses a spatial object in three dimensions is the minimum bounding box (MBB). Table access by index rowid operation means that after the alternative records that satisfy the spatial filter conditions of the filter conditions are queried and selected, the process goes back to the primary key table for further querying to get all fields and to determine whether other non-spatial filter conditions in the filter conditions are satisfied. Take a database of clustered index tables as an example. Table access by index rowid operation for clustered index tables is inefficient and slow, which makes the query of spatial data inefficient. The so-called clustered index table is a commonly used format for organizing database tables, which means that all records in the database table are organized according to the order of the primary key. Indexing is used to store data in a database table, and the data is indexed using the primary key of the database table. The database index generated based on the clustered index table is a secondary index of the database table. The secondary index refers to a non-primary key index. Furthermore, when the number of records that match the spatial filter condition during a query is relatively large, the CPU and IO overhead of table access through index rowid calculation to obtain the complete records is relatively large, resulting in a relatively low efficiency of spatial data query. It should be noted that the database index processing method provided by the present application can also be applied to a heap table.
[0038] In the database index processing method proposed by the present application, the leaf nodes of the obtained tree-structured spatial index of the database table store spatial data that meets the spatial filter condition, and queries that meet certain conditions directly obtain query results from the tree-structured spatial index of the database table. It should be noted that not all queries require table access by index rowid calculation to obtain complete records, which makes transactions involving queries of spatial data faster and more efficient for spatial filtering queries.
[0039] This step is to determine the database table for which the database index is created, and the database table contains a spatial field. In our example, we use database table test of database A (test is table name). Table test uses GEOM field to store spatial data of Geographic Information System (GIS). GIS spatial data is classified as Geometry data type. GEOM is field ID (or called field name) of table test. Geometry is a spatial data type supported by the database, which can be longitude and latitude information that represents a geographic location. Table test further contains other non-spatial fields, namely ID of type integer, NAME of type character with length of 500, PRICE of type double, and regular fields such as ID int, NAME varchar(500), PRICE double, VERSION int, primary key (id) corresponding to ID used as primary key, respectively. As such, the records of table test contain identification, name, price, and location information of the object. The GEOM field is a spatial field, while other fields that store non-spatial data are regular or non-spatial fields.
[0040] Step S102: For the database table, a spatial filter condition including a spatial field ID is obtained.
[0041] This step is to determine the spatial filter conditions, also known as filter conditions, for generating the spatial index.
[0042] In the implementation method provided by the embodiment of the present application, the spatial filter condition includes a spatial field, and the index columns of the tree-structured spatial index obtained in the corresponding subsequent step include this spatial field.
[0043] In another implementation method provided by the embodiment of the present application, the spatial filter condition includes a spatial field prefix. Alternatively, the spatial data can be stored in a tree structure index that is generated later using the spatial field prefix. In other words, the constraint condition of the spatial data stored in the index can be defined or specified through the spatial field prefix. Specifically, the constraint condition is determined according to the actual situation of the spatial data of the spatial field in the database table record, and taking into account the balance between query efficiency and space occupancy. For example, when the space occupancy is still available, the condition for storing the spatial data in the index is relaxed, and as much spatial data as possible is stored in the index, thereby improving the query efficiency.
[0044] Furthermore, the spatial filter condition further includes at least one of a non-spatial field and a non-spatial field prefix. The spatial indexes generated according to different spatial filter conditions in subsequent steps include different field formats. If the spatial filter condition refers to a spatial field prefix, the resulting spatial index is a spatial prefix index, and the index column of the spatial prefix index includes the spatial field prefix. If the spatial filter condition refers to a spatial field prefix and a non-spatial field, a spatial field prefix and a non-spatial field prefix, a spatial field prefix, a non-spatial field, or a non-spatial field prefix, the resulting spatial index is a composite prefix spatial index. The index column of the composite prefix spatial index includes a spatial field prefix, and further includes at least one of a non-spatial field and a non-spatial field prefix.
[0045] In the embodiment of the present application, the index creation command information may be obtained at the stage when the database table is created, or it may be obtained after the database table is created, or after the database table is created and data is inserted. This process specifically includes: creating a database table according to database table creation commands, the database table creation commands including an index creation command for generating a tree-structured spatial index; or Creating a tree-structured spatial index in accordance with the index creation command.
[0046] Continuing to use the database table test in database A as an example, create the test using the following command to get the index creation command information for creating the spatial index sck: Create table test( ID int, NAME varchar(500), PRICE double, GEOM.Geometry, VERSION int, Primary key(id), Spatial key sck (Geom(30), version) );
[0047] The create index command information for the above spatial index sck included in the create command for table test includes a 30 byte prefix for the spatial field GEOM, the VERSION field, and the primary key id that is automatically included as a secondary index. It can also be created by using "Create index" after table test is created or after data is inserted into table test. For example, the create index command information for spatial index sck1 includes a 30 byte prefix for the spatial field GEOM, the PRICE field, and the primary key id that is automatically included as a secondary index. The command is: create spatial key sck1(geom(20), price).
[0048] Step S103: Generate a tree-structured spatial index for the database table according to the spatial filter condition, and the leaf nodes of the tree-structured spatial index store the spatial data that meets the spatial filter condition and the primary key ID.
[0049] This step is to create a tree-structured spatial index that stores the spatial data.
[0050] In an embodiment of the present application, when a spatial filter condition includes a spatial field and a non-spatial field, the tree-structured spatial index of a database table is specifically: obtaining information of a spatial field used to generate a tree-structured spatial index according to a spatial filter condition; Obtaining information about non-spatial fields used to generate a tree-structured spatial index; generating a composite spatial index for the database table according to information of the spatial field and information of the non-spatial field, where an index column of the spatial composite index includes the spatial field and the non-spatial field; A composite spatial index is used as a tree-structured spatial index, and is generated through the process of.
[0051] In an embodiment of the present application, when the spatial filter condition includes information of spatial field prefixes and information of non-spatial fields, the tree-structure spatial index of the database table is specifically: Obtaining spatial field prefix information used to generate a tree-structured spatial index according to a spatial filter condition; Obtaining information about non-spatial fields used to generate a tree-structured spatial index; generating a composite prefix spatial index according to information of the spatial field prefix and information of the non-spatial field, where an index column of the composite prefix spatial index includes the spatial field prefix and the non-spatial field; A spatial compound prefix index is used as a tree-structured spatial index, and is generated through the process of.
[0052] In a specific implementation method provided by an embodiment of the present application, index columns of the generated tree-structured spatial index include a spatial field, and non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving spatial data and a page ID for searching the next level page.
[0053] In another specific implementation method provided by an embodiment of the present application, the index columns of the generated tree-structured spatial index include spatial field prefix information, and the non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving spatial data and a page ID for searching the next level page. The tree-structured spatial index of the database table specifically includes: Obtaining spatial field prefix information used to generate a tree-structured spatial index according to a spatial filter condition; generating a spatial prefix index for the database table according to the spatial field prefix information, where an index column of the spatial prefix index includes the spatial field prefix information; It is generated through the process of using a spatial prefix index as a tree-structured spatial index and
[0054] In addition, the spatial filter condition includes a minimum bounding rectangle operation type filter condition. Therefore, the process of generating a spatial prefix index for a database table according to spatial field prefix information includes: performing minimum bounding box filtering on the database table according to the minimum bounding box type filter condition to obtain an alternative spatial field that satisfies the minimum bounding box type filter condition; performing a standard byte stream encoding for geospatial information on the spatial data stored in the alternative spatial field; generating a spatial prefix index for the database table according to the spatial data on which standard byte stream encoding for geospatial information has been performed and the spatial field prefix information;
[0055] The so-called geospatial information standard byte stream refers to Well-known Binary (WKB), which uses a continuous binary stream to represent geometric information.
[0056] In a specific implementation method provided by an embodiment of the present application, the spatial field prefix information includes a condition for indicating the length of the spatial data stored in the spatial field. Therefore, generating a spatial prefix index of a database table according to the spatial data that is standard byte stream encoded for geospatial information and the spatial field prefix information specifically includes: Obtaining a length of spatial data that has been subjected to a standard byte stream encoding for geospatial information; Obtaining a length condition according to the spatial field prefix information; If the length of the spatial data on which standard byte stream encoding for geospatial information has been performed satisfies the length condition, storing the spatial data that satisfies the length condition in a leaf node of the spatial prefix index; Otherwise, the leaf nodes of a spatial prefix index do not store any spatial data.
[0057] Continuing to use the database table test of database A as an example. A tree-structured compound-prefix spatial index is generated based on GEOM, VERSION, and NAME. The structure of the index is shown in FIG. 2. FIG. 2 shows a schematic structural diagram of a tree-structured compound-prefix spatial index. The structure of the compound-prefix spatial index is that of an R-tree index. In this figure, 201 indicates that the root is the root node of an R-tree that stores the maximum rectangular space. The non-leaf node indicated by 202 only stores the minimum bounding rectangle (MBR) for spatial retrieval and the pageid (page identification) for searching the next page. The content stored in the leaf node indicated by 203 is different from the content stored in the non-leaf node indicated by 202. The content stored in the leaf node indicated by 203 includes not only the MBR but also the spatial data of the constraint included in the spatial field prefix, which is further shown in FIG. 20. 3In this example, the content specifically includes the VERSION and NAME fields, as well as the 20 3 Includes the primary key PK that is automatically included in a composite prefix spatial index as a secondary index, such as the PK included in the . In this example, the primary key of the table test is ID, so the leaf nodes of a given composite prefix spatial index also include the ID field.
[0058] Based on the above first embodiment, the second embodiment of the present application further provides a database query processing method.
[0059] Please refer to Fig. 3, which illustrates a database query processing method provided by the second embodiment of the present application. Since this embodiment is based on the first embodiment, its description is relatively brief. For relevant parts, reference can be made to the corresponding description of the first embodiment.
[0060] The database query processing method provided by the second embodiment of the present application includes steps S301 to S304.
[0061] Step S301: Determine a database table from which spatial data is queried, and the database table includes a spatial field for storing the spatial data.
[0062] This step is to determine the database tables against which the spatial data will be queried.
[0063] In this embodiment of the present application, the database table is determined by obtaining a query command. As an example, the database table test of database A is still used. An example of the query command is as follows: selectID, GEOM, VERSION from test where MBRIntersects(GEOM,,ST_GeomFromText('POLYGON((113.22779059410095 23.077155641028952, 113.22927117347716 23.077155641028952, 113.22927117347716 23.078517734365768, 113.22779059410095 23.078517734365768, 113.22779059410095 23.077155641028952))', 4326))and version(2, 3); The records of table test include object identification, name, price, and location information, and table test uses spatial field GEOM to store GIS spatial data including longitude and latitude information. Table test further includes other non-spatial fields: ID (identification) of type integer, NAME (name) of type character with length 500, PRICE (price) of type double, and regular fields of ID int, NAME varchar(500), PRICE double, VERSION int, primary key (id), and other fields corresponding to the primary key specified as ID field, respectively. The above query command is to select the recorded ID, GEOM, and VERSION information from table test that meets the query condition specified by the where clause. The query condition in this example includes spatial query condition and non-spatial query condition.
[0064] Step S302: For a database table, a query condition including a spatial query field is obtained.
[0065] This step is to determine the query conditions that include a spatial query field.
[0066] In an embodiment of the present application, the spatial query information of the query condition includes a spatial query field, and the spatial query information is specifically a minimum bounding rectangle operation including the spatial query field.
[0067] Continuing to use the query command from Database Table Test in Database A as an example:
[0068] MBRIntersects(GEOM,,ST_GeomFromText('POLYGON ((113.22779059410095 23.077155641028952, 113.22927117347716 23.077155641028952, 113.22927117347716 23.078517734365768, 113.22779059410095 23.078517734365768, 113.22779059410095 23.077155641028952))', 4326)) The where clause in the above command is to determine whether the minimum bounding rectangle operation is an operation that involves intersection or overlap.
[0069] In an embodiment of the present application, the query condition further includes at least one of a non-spatial field and a non-spatial field prefix.
[0070] Step S303: Obtain a tree-structured spatial index of the database table, and the leaf nodes of the tree-structured spatial index store the spatial data.
[0071] This step is to obtain a tree-structured spatial index.
[0072] In the embodiment of the present application, this step specifically includes the following processes: obtaining a query condition of a database table, determining that the query condition includes a spatial query field, and obtaining a spatial index or a composite spatial index established for the database table. Specifically, the index column of the tree-structured spatial index includes a spatial field, and the non-leaf node of the tree-structured spatial index stores a minimum bounding rectangle for retrieving spatial data and a page ID for searching the next level page. Preferably, the leaf node further includes a primary key ID.
[0073] Continuing to use the database table test of database A as an example. In the table test, a tree-structured compound prefix spatial index is obtained, which is generated based on GEOM, VERSION, and NAME. The structure of the index is shown in FIG. 2. FIG. 2 shows a schematic structural diagram of a tree-structured compound prefix spatial index. The structure of the compound prefix spatial index is that of an R-tree index. In this diagram, 201 indicates that the root is the root node of the R-tree, which stores the maximum rectangular space. The non-leaf node, indicated by 202, stores only the minimum bounding rectangle (MBR) for spatial retrieval and the pageid (page identification) for searching the next page. The content stored in the leaf node, indicated by 203, is different from the content stored in the non-leaf node, indicated by 202. The content stored in the leaf node, indicated by 203, includes not only the MBR, but also the spatial data of the constraint included in the spatial field prefix, which further certainly includes the conventional non-spatial fields, such as the VERSION field, the NAME field, and the primary key PK, which are automatically included in the compound prefix spatial index as secondary indexes. Since the primary key of the table test is ID, the leaf nodes of a particular compound prefix spatial index also contain the ID field.
[0074] Step S304: Query the tree-structured spatial index according to the query condition to obtain the query result.
[0075] This step is to query the tree-structured spatial index according to the query condition.
[0076] In an embodiment of the present application, the query condition further includes a non-spatial field, and the query result is specifically: Obtaining the spatial fields of the query criteria; and determining whether the spatial field matches a spatial field ID of an index column of the tree-structured spatial index; if so, querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain a query result that satisfies the query condition; If not, obtain an alternative record of the non-spatial query field that matches the query condition in the database table, and obtain a query result that meets the query condition from the alternative record according to the spatial query field of the query condition. In the embodiment of the present application, obtaining a query result that meets the query condition from the alternative record specifically includes: performing spatial calculations on the data of the alternate row records and retrieving row records from the alternate row records that match the spatial query field according to the calculation results; using row records that satisfy the spatial query field as query results that satisfy the query condition; and processing.
[0077] In an embodiment of the present application, when it is determined that the spatial field matches the spatial field ID of the index column of the tree-structured spatial index, querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain a query result that satisfies the query condition: Obtaining a non-spatial query field of the query condition; determining whether the spatial query field and the non-spatial query field are index columns included in a composite spatial index for the database table; if so, determining that the query condition satisfies a spatial index query mode of the database table, and querying the composite spatial index of the database table using a covering index scan according to the query condition; If not, the process goes through the steps of: querying from the composite spatial index of the database table according to the query condition to find an alternate record that satisfies the query condition; and further querying back to the database table according to the primary key of the alternate record to obtain a complete row record that satisfies the query condition.
[0078] Specifically, querying a composite spatial index on a database table using a covering index scan, according to a query condition, Determining whether the spatial query field is a spatial field of a composite spatial index of the queried database table according to the spatial query field; if so, querying the composite spatial index using a covering index scan according to the length condition contained in the prefix information of the spatial query field; If not, it is done through querying the composite spatial index of the database table using a covering index scan and processing.
[0079] In the embodiment of the present application, specifically, querying a composite spatial index using a covering index scan according to the length condition included in the prefix information of a spatial query field includes: Obtaining a length condition included in prefix information of a spatial query field; determining whether a length of a row record of the composite spatial index satisfies a length condition, and if so, using the row record as a query result of a covering index scan; If not, it is done through querying the database table according to the primary key information and processing.
[0080] Please refer to Fig. 4, which shows a flowchart of a specific implementation of the database query processing method provided by the second embodiment of the present application. In this figure, the implementation includes the following steps:
[0081] S401, Query Start, i.e., a query command is received and the query process is started.
[0082] S402. Query optimization, i.e., the query command description is deciphered and the query terms are divided into various tokens to be used in subsequent steps.
[0083] S403. Determine whether to use spatial index to query. In the embodiment of the present application, if the query condition includes geometric operators for spatial data, such as intersection, containment, direction, distance, distance classification, etc., determine that spatial index is used preferentially, if so, proceed to S404, if not, proceed to S404-1.
[0084] S404. Determine whether the composite spatial index includes a query object field, that is, whether the composite spatial index includes a field that needs to be queried in the query command. In the embodiment of the present application, it is determined whether the composite spatial index of the database table includes a field (or a column of the database table) that needs to be queried in the query command according to each token obtained through splitting. If the composite spatial index includes a field that needs to be queried in the query command, proceed to S405; if the composite spatial index does not include a field that needs to be queried in the query command, proceed to S405-1.
[0085] S404-1. Enter the processing flow for other non-spatial field indexes. That is, the spatial index query cannot be executed preferentially, and the query must be based on the non-spatial field. In the embodiment of the present application, the following operations are performed: obtain the alternative records of the non-spatial query fields that match the query condition in the database table, and obtain the query results that meet the query condition according to and from the alternative records according to the spatial query field of the query condition. Specifically, performing spatial calculations on the data of the alternate row records and retrieving row records from the alternate row records that match the spatial query field according to the calculation results; The method includes using row records that satisfy the spatial query field as query results that satisfy the query condition, and processing the.
[0086] This process requires querying the complete data recorded in each row, and then using standard spatial functions to calculate and determine if the query conditions are met, upon which geometric spatial operations such as intersection, containment, direction, distance, distance classification, etc. can be performed.
[0087] S405: Determine whether a spatial field needs to be queried in the query command. If a spatial field needs to be obtained in the query command, proceed to S406; if a spatial field does not need to be obtained in the query command, proceed to S406-1.
[0088] S405-1. Perform table access by index rowid operation, which specifically means that after the alternative records that satisfy the spatial query conditions of the query condition are queried and selected, the process goes back to the primary key table for further query to get all fields and determine whether other non-spatial query conditions in the query condition are satisfied.
[0089] S406: Determine whether the length of the recorded spatial data meets the length condition of the spatial field prefix. If the length of the spatial data meets the length condition of the spatial field prefix, proceed to S406-1; if the length of the spatial data does not meet the length condition of the spatial field prefix, proceed to S405-1.
[0090] S406-1. Perform a covering index scan operation, i.e., perform a covering index scan on the composite spatial index to obtain the required query result.
[0091] Continuing to use the query command of database table test of database A as an example. The above select command is to select the recorded ID, GEOM and VERSION information from table test that meets the query condition specified by the where clause. The query condition in this example includes a spatial query condition and a non-spatial query condition. The spatial query condition is the MBRIntersects operation, and the non-spatial query condition is the VERSION condition, i.e., the version in (2, 3). When the table test is created, a composite prefix spatial index sck is created. The sck records the 30-byte prefix of the GEOM field, the VERSION, and the primary key ID that is automatically included as a secondary index. The where condition of the query first has a filter condition of the minimum bounding rectangle operation that meets the query filtering of the spatial index, and then the other filter conditions and the queried content are the index columns of this sck index. As a result, S405 is executed. Further, it is determined whether the spatial index query mode can be used. It is further determined whether the spatial fields of the composite spatial index are filtered by conditions that the spatial index can perform, such as bounding box operation, distance operation, etc., and whether the composite spatial index further includes filtering of other normal fields. During the execution of S405, since the geom field is selected, the process proceeds to S406 to further determine the spatial prefix length condition. If the resulting geom that satisfies the bounding box filtering in the index is less than 30 bytes after being encoded using wkb, for example, a point (113.228, 23.078) that has a corresponding wkb length of 25, the complete geom wkb information can be recorded in the leaf node of the sck index. In this case, the process proceeds to S406-1 for covering index scan.If it is a very large polygon and the length of the wkb encoding exceeds 30 bytes, a record of this situation is marked on the sck index and the table access by index rowid operation is performed according to this mark, which means the process goes to S405-1 and checks the primary key index again to get the complete record of geom.
[0092] According to the database index processing method provided by the first embodiment of the present application, the third embodiment of the present application further provides a database index processing device.
[0093] Please refer to Fig. 5, which shows a schematic diagram of a database index processing device provided according to the third embodiment of the present application. This device embodiment is basically similar to the method embodiment, so the description is relatively brief. For relevant parts, reference can be made to the corresponding description of the method embodiment.
[0094] The present application provides a database index processing device, the device comprising: a database table determination unit 501 configured to determine a database table on which a database index is to be created, the database table including a spatial field for storing spatial data; A filter condition obtaining unit 502 configured to obtain a spatial filter condition including a spatial field ID for a database table; The index generating unit 503 is configured to generate a tree-structured spatial index for the database table according to a spatial filter condition, wherein a leaf node of the tree-structured spatial index stores spatial data that satisfies the spatial filter condition and a primary key ID.
[0095] In this specification, the spatial filter condition includes spatial field prefix information, and the index generating unit 503 specifically: Obtaining spatial field prefix information used to generate a tree-structured spatial index according to a spatial filter condition; generating a spatial prefix index for the database table according to the spatial field prefix information, where an index column of the spatial prefix index includes the spatial field prefix information; and using a spatial prefix index as the tree-structured spatial index.
[0096] In this specification, the spatial filter condition includes a minimum bounding rectangle operation type filter condition, and the index generation unit 503 specifically: performing minimum bounding box filtering on the database table according to the minimum bounding box type filter condition to obtain an alternative spatial field that satisfies the minimum bounding box type filter condition; performing a standard byte stream encoding for geospatial information on the spatial data stored in the alternative spatial field; and generating a spatial prefix index for the database table according to the spatial data on which a standard byte stream encoding for geospatial information has been performed and the spatial field prefix information.
[0097] In this specification, the spatial field prefix information includes a condition for indicating the length of the spatial data stored in the spatial field, and the index generating unit 503 specifically includes: Obtaining a length of spatial data that has been subjected to a standard byte stream encoding for geospatial information; Obtaining a length condition according to the spatial field prefix information; if the length of the spatial data on which standard byte stream encoding for geospatial information has been performed satisfies the length condition, storing the spatial data that satisfies the length condition in a leaf node of the spatial prefix index; Otherwise, the leaf nodes of a spatial prefix index do not store any spatial data.
[0098] In this specification, the index generating unit 503 specifically includes: obtaining information of a spatial field used to generate a tree-structured spatial index according to a spatial filter condition; Obtaining information about non-spatial fields used to generate a tree-structured spatial index; generating a composite spatial index for the database table according to information of the spatial field and information of the non-spatial field, where an index column of the spatial composite index includes the spatial field and the non-spatial field; and using the composite spatial index as a tree-structured spatial index.
[0099] In this specification, the index generating unit 503 specifically includes: Obtaining spatial field prefix information used to generate a tree-structured spatial index according to a spatial filter condition; Obtaining information about non-spatial fields used to generate a tree-structured spatial index; generating a composite prefix spatial index according to information of the spatial field prefix and information of the non-spatial field, where an index column of the composite prefix spatial index includes the spatial field prefix and the non-spatial field; and using a compound prefix spatial index as the tree-structured spatial index.
[0100] The index columns of the tree-structured spatial index include a spatial field, and the non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving the spatial data, and a page ID for searching the next level page.
[0101] Herein, the device further comprises a command unit, the command unit comprising: creating a database table according to database table creation commands, the database table creation commands including an index creation command for generating a tree-structured spatial index; or and creating a tree-structured spatial index in accordance with the index creation command.
[0102] According to the database query processing method provided by the second embodiment of the present application, the fourth embodiment of the present application further provides a database query processing apparatus.
[0103] Please refer to Fig. 6, which shows a schematic diagram of a database query processing apparatus provided according to the fourth embodiment of the present application. This apparatus embodiment is basically similar to the method embodiment, so the description will be relatively brief. For relevant parts, reference can be made to the corresponding description of the method embodiment.
[0104] The database query processing device shown in FIG. A database table determination unit 601 configured to determine a database table to which spatial data is queried, the database table including a spatial field for storing the spatial data; A query condition determination unit 602 configured to obtain a query condition including a spatial query field for the database table; an index obtaining unit 603 configured to obtain a tree-structured spatial index of a database table, where leaf nodes of the tree-structured spatial index store spatial data; A query unit 604 configured to query the tree-structured spatial index according to a query condition to obtain a query result.
[0105] The query condition further includes a non-spatial field, and the query unit 604 specifically: Obtaining the spatial fields of the query criteria; and determining whether the spatial field matches a spatial field ID of an index column of the tree-structured spatial index; if so, querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain a query result that satisfies the query condition; Otherwise, the method is configured to obtain an alternative record for the non-spatial query field that matches the query condition in the database table, and obtain a query result that satisfies the query condition according to the spatial query field of the query condition and from the alternative record.
[0106] In this specification, the query unit 604 specifically includes: obtaining a non-spatial query field of a query condition; determining whether the spatial query field and the non-spatial query field are index columns included in a composite spatial index for the database table; if so, determining that the query condition satisfies a spatial index query mode of the database table, and querying the composite spatial index of the database table using a covering index scan according to the query condition; If not, it is configured to query from the composite spatial index of the database table according to the query condition to find an alternate record that satisfies the query condition, and further query back to the database table according to the primary key of the alternate record to obtain a complete row record that satisfies the query condition.
[0107] In this specification, the query unit 604 includes a covering index scan subunit, which determines whether a spatial field of a composite spatial index of a database table is queried according to a spatial query field; if so, querying the composite spatial index using a covering index scan according to the length condition contained in the prefix information of the spatial query field; If not, then it is configured to query the composite spatial index of the database table using a covering index scan.
[0108] In this specification, the covering index scan subunit specifically includes: obtaining the length condition included in the prefix information of the spatial query field; The system is configured to determine whether a length of a row record of a composite spatial index satisfies a length condition, and if so, use the row record as a query result of a covering index scan, and if not, query the database table according to the primary key information.
[0109] In this specification, the query unit 604 specifically includes: performing spatial calculations on the data of the alternate row records and retrieving row records from the alternate row records that satisfy the spatial query field according to the calculation results; and using row records that satisfy the spatial query field as query results that satisfy the query condition.
[0110] As used herein, the spatial query information of a query condition is a minimum bounding rectangle operation that includes the spatial query field.
[0111] The index columns of the tree-structured spatial index include a spatial field, and the non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving the spatial data, and a page ID for searching the next level page.
[0112] Herein, the leaf node further includes a primary key ID.
[0113] Based on the above embodiment, the fifth embodiment of the present application further provides an electronic device for implementing a database index processing method. Please refer to Figure 7, which shows a schematic diagram of the electronic device provided by the fifth embodiment.
[0114] The fifth embodiment of the present application is described in a relatively concise manner. For relevant parts, reference can be made to the corresponding descriptions of the preceding embodiments.
[0115] A fifth embodiment of the present application is An electronic device is provided, comprising a memory 701 and a processor 702, The memory 701 is configured to store computer-executable instructions, and the processor 702 is determining a database table for which a database index is to be created, the database table including a spatial field for storing spatial data; Obtaining a spatial filter condition for a database table, the spatial filter condition including a spatial field ID; The method is configured to execute the following computer-executable commands: generate a tree-structured spatial index for the database table according to the spatial filter condition, wherein leaf nodes of the tree-structured spatial index store spatial data that satisfies the spatial filter condition and a primary key ID.
[0116] Optionally, the spatial filter condition includes spatial field prefix information, and the processor 702: Obtaining spatial field prefix information used to generate a tree-structured spatial index according to a spatial filter condition; generating a spatial prefix index for the database table according to the spatial field prefix information, where an index column of the spatial prefix index includes the spatial field prefix information; and using the spatial prefix index as the tree-structured spatial index.
[0117] Optionally, the spatial filter condition includes a minimum bounding rectangle operation type filter condition, and the processor 702: performing minimum bounding box filtering on the database table according to the minimum bounding box type filter condition to obtain an alternative spatial field that satisfies the minimum bounding box type filter condition; performing a standard byte stream encoding for geospatial information on the spatial data stored in the alternative spatial field; and generating a spatial prefix index for the database table according to the spatial data performed with the standard byte stream encoding for geospatial information and the spatial field prefix information.
[0118] Optionally, the spatial field prefix information includes a term to indicate a length of the spatial data stored in the spatial field, and the processor 702: Obtaining a length of spatial data that has been subjected to a standard byte stream encoding for geospatial information; Obtaining a length condition according to the spatial field prefix information; if the length of the spatial data subjected to the standard byte stream encoding for geospatial information satisfies the length condition, store the spatial data that satisfies the length condition in a leaf node of the spatial prefix index; Otherwise, the leaf nodes of a spatial prefix index do not store any spatial data.
[0119] Optionally, the processor 702 may: obtaining information of a spatial field used to generate a tree-structured spatial index according to a spatial filter condition; Obtaining information about non-spatial fields used to generate a tree-structured spatial index; generating a composite spatial index for the database table according to information of the spatial field and information of the non-spatial field, where an index column of the spatial composite index includes the spatial field and the non-spatial field; and using the composite spatial index as the tree-structured spatial index.
[0120] Optionally, the processor 702 may: Obtaining spatial field prefix information used to generate a tree-structured spatial index according to a spatial filter condition; Obtaining information about non-spatial fields used to generate a tree-structured spatial index; generating a composite prefix spatial index according to information of the spatial field prefix and information of the non-spatial field, where an index column of the composite prefix spatial index includes the spatial field prefix and the non-spatial field; and using the compound-prefix spatial index as the tree-structured spatial index.
[0121] Optionally, index columns of the tree-structured spatial index include a spatial field, and non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving spatial data and a page ID for searching the next level page.
[0122] Optionally, the processor 702 may: creating a database table according to database table creation commands, the database table creation commands including an index creation command for generating a tree-structured spatial index; or The system is further configured to execute computer-executable commands for creating a tree-structured spatial index according to the index creation command.
[0123] Based on the foregoing embodiment, the sixth embodiment of the present application further provides an electronic device for implementing the database query processing method, the structure of which is similar to that shown in FIG.
[0124] The sixth embodiment of the present application is described in a relatively concise manner. For relevant parts, reference can be made to the corresponding descriptions of the preceding embodiments.
[0125] The sixth embodiment of the present application is Providing an electronic device comprising a memory and a processor, The memory is configured to store computer-executable commands and the processor is configured to execute the computer-executable commands; The memory is configured to store computer-executable instructions, and the processor is determining a database table from which the spatial data is queried, the database table including a spatial field for storing the spatial data; obtaining a query condition for a database table, the query condition including a spatial query field; Obtaining a tree-structured spatial index for a database table, the leaf nodes of the tree-structured spatial index storing spatial data; The method is configured to execute computer-executable commands of: querying the tree-structured spatial index according to the query condition to obtain a query result.
[0126] Optionally, the leaf node further includes a primary key ID.
[0127] Optionally, the query condition further comprises a non-spatial field, and the processor: Obtaining the spatial fields of the query criteria; and determining whether the spatial field matches a spatial field ID of an index column of the tree-structured spatial index; if so, querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain a query result that satisfies the query condition; If not, the method is further configured to execute the computer-executable commands to obtain alternative records for the non-spatial query fields in the database table that match the query condition, and to obtain query results that satisfy the query condition according to the spatial query field of the query condition and from the alternative records.
[0128] Optionally, the processor: Obtaining a non-spatial query field of the query condition; determining whether the spatial query field and the non-spatial query field are index columns included in a composite spatial index for the database table; if so, determining that the query condition satisfies a spatial index query mode of the database table, and querying the composite spatial index of the database table using a covering index scan according to the query condition; If not, the method is further configured to execute the computer-executable commands of: querying from the composite spatial index of the database table according to the query condition to find an alternate record that satisfies the query condition, and further querying back to the database table according to the primary key of the alternate record to obtain a complete row record that satisfies the query condition.
[0129] Optionally, the processor: Determining whether the spatial query field is a spatial field of a composite spatial index of the queried database table according to the spatial query field; if so, querying the composite spatial index using a covering index scan according to the length condition contained in the prefix information of the spatial query field; If not, query the composite spatial index for the database table using a covering index scan.
[0130] Optionally, the processor: Obtaining a length condition included in prefix information of a spatial query field; determining whether a length of a row record of the composite spatial index satisfies a length condition, and if so, using the row record as a query result of a covering index scan; If not, querying the database table according to the primary key information.
[0131] Optionally, the processor: performing spatial calculations on the data of the alternate row records and retrieving row records from the alternate row records that match the spatial query field according to the calculation results; and using the row records that satisfy the spatial query field as query results that satisfy the query condition.
[0132] Optionally, the spatial query information of the query condition is a minimum bounding rectangle operation that includes the spatial query field.
[0133] Optionally, index columns of the tree-structured spatial index include a spatial field, and non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving spatial data and a page ID for searching the next level page.
[0134] The seventh embodiment of the present application further provides a storage device described in a relatively simple manner. For relevant parts, reference can be made to the corresponding descriptions of the preceding embodiments.
[0135] The present application provides a storage device having stored commands, the commands comprising: determining a database table for which a database index is to be created, the database table including a spatial field for storing spatial data; obtaining a spatial filter condition for a database table, the spatial filter condition including a spatial field ID; The method may be written by the processor to perform the steps of: generating a tree-structured spatial index for the database table according to the spatial filter condition, wherein leaf nodes of the tree-structured spatial index store spatial data that satisfies the spatial filter condition and a primary key ID.
[0136] The eighth embodiment of the present application further provides a storage device described in a relatively simple manner. For relevant parts, reference can be made to the corresponding descriptions of the preceding embodiments.
[0137] The present application provides a storage device having stored commands, the commands being capable of being written by a processor to perform the following steps: The memory is configured to store computer-executable instructions, and the processor is determining a database table from which the spatial data is queried, the database table including a spatial field for storing the spatial data; obtaining a query condition for a database table, the query condition including a spatial query field; Obtaining a tree-structured spatial index for a database table, the leaf nodes of the tree-structured spatial index storing spatial data; The method is configured to execute computer-executable commands of: querying the tree-structured spatial index according to the query condition to obtain a query result.
[0138] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, a network interface, and memory.
[0139] The memory may include volatile memory on a computer-readable medium, such as random access memory (RAM), and / or non-volatile memory, such as read only memory (ROM) or flash random access memory (flash RAM), etc. The memory is one example of a computer-readable medium.
[0140] 1. Computer-readable media further includes non-volatile and volatile media, removable and non-removable media employing any method or technology to achieve information storage. Information may be computer-readable commands, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical memory, magnetic cassette tape, magnetic tape, magnetic disk storage or other magnetic storage device, or any other non-transmission medium that may be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0141] 2. It should be understood by those skilled in the art that the embodiments of the present application may be provided as a method, a system, or a computer program product. Thus, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware elements. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer usable storage mediums (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer usable program code thereon.
[0142] Although the present application has been disclosed above in the preferred embodiment, the present application should not be limited thereby.Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of the present application.Therefore, the protection scope of the present application is defined by the claims of the present application. [Explanation of symbols]
[0143] 501 Database Table Judgment Unit 502 Filter Condition Acquisition Unit 503 Index Generation Unit 601 Database Table Judgment Unit 602 Query Condition Decision Unit 603 Index Acquisition Unit 604 Query Unit 701 Memory 702 Processor
Claims
1. A computer implemented method for processing a database index, the method comprising: determining a database table for which a database index is to be created, the database table including a spatial field for storing spatial data; obtaining a spatial filter condition for the database table, the spatial filter condition including a spatial field ID; generating a tree-structured spatial index for the database table according to the spatial filter condition, wherein leaf nodes of the tree-structured spatial index store spatial data that satisfies the spatial filter condition and a primary key ID.
2. the spatial filter condition includes spatial field prefix information; generating the tree-structured spatial index of the database table according to the spatial filter condition; obtaining spatial field prefix information used to generate the tree-structured spatial index according to the spatial filter condition; generating a spatial prefix index for the database table according to the spatial field prefix information, wherein an index column of the spatial prefix index includes the spatial field prefix information; and using the spatial prefix index as the tree-structured spatial index.
3. the spatial filter condition includes a minimum bounding rectangle operation type filter condition, generating the spatial prefix index of the database table according to the spatial field prefix information; performing minimum bounding box filtering on the database table according to the filter condition of the minimum bounding rectangle operation type to obtain an alternative spatial field that satisfies the filter condition of the minimum bounding rectangle operation type; performing a standard byte stream encoding for geospatial information on the 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 has been performed and the spatial field prefix information.
4. the spatial field prefix information includes a term for indicating a length of spatial data stored in the spatial field; generating the spatial prefix index of the database table according to the spatial data on which the standard byte stream encoding for geospatial information has been performed and the spatial field prefix information; obtaining a length of the spatial data on which the standard byte stream encoding for geospatial information has been performed; Obtaining a length condition according to the spatial field prefix information; in response to determining that the length of the spatial data on which the standard byte stream encoding for geospatial information has been performed satisfies the length condition, storing the spatial data that satisfies the length condition in a leaf node of the spatial prefix index; or and determining not to store the spatial data in the leaf node of the spatial prefix index in response to determining that the length of the spatial data for which the standard byte stream encoding for geospatial information is not performed satisfies the length condition.
5. generating the tree-structured spatial index of the database table according to the spatial filter condition; obtaining spatial field information used to generate the tree-structured spatial index according to the spatial filter condition; obtaining information for non-spatial fields used to generate the tree-structured spatial index; generating a composite spatial index for the database table according to the information of the spatial field and the information of the non-spatial field, wherein index columns of the composite spatial index include the spatial field and the non-spatial field; and using the composite spatial index as the tree-structured spatial index.
6. generating the tree-structured spatial index of the database table according to the spatial filter condition; obtaining spatial field prefix information used to generate the tree-structured spatial index according to the spatial filter condition; obtaining information for non-spatial fields used to generate the tree-structured spatial index; generating a composite spatial prefix index according to the information of the spatial field prefixes and the information of the non-spatial fields, wherein an index column of the composite spatial prefix index includes the spatial field prefixes and the non-spatial fields; and using the composite spatial prefix index as the tree-structured spatial index.
7. an index column of the tree-structured spatial index includes a spatial field; 2. The method of claim 1, wherein non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving the spatial data and a page ID for retrieving a next level page.
8. creating the database table according to a database table creation command, the database table creation command including a create index command for generating the tree-structured spatial index; or The method of claim 1 , further comprising creating the tree-structured spatial index according to the index creation command.
9. A computer implemented method for processing database queries, the method comprising: determining a database table from which spatial data is queried, the database table including a spatial field for storing the spatial data and a non-spatial field; obtaining a query condition for the database table, the query condition including a spatial query field; obtaining a tree-structured spatial index for the database table, the leaf nodes of the tree-structured spatial index storing spatial data; Querying the tree-structured spatial index according to the query condition to obtain a query result; Including, Querying the tree-structured spatial index to obtain the query results, obtaining 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; responsive to determining that the spatial field matches a spatial field ID of an index column of the tree-structured spatial index, querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain a query result that satisfies 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 in the database table that matches the query condition, and obtaining a query result that satisfies the query condition according to the spatial query field of the query condition and from the alternative record; A method comprising:
10. Querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain the query results that satisfy the query condition. obtaining a non-spatial query field of the query term; determining whether the spatial query field and the non-spatial query field are in index columns included in the composite spatial index of the database table; in response to determining that the spatial query field and the non-spatial query field are in index columns included in the composite spatial index of the database table, determining that the query condition satisfies a spatial index query mode of the database table and querying the composite spatial index of the database table using a covering index scan in accordance with the query condition; or 10. The method of claim 9, comprising: in response to determining that the spatial query field and the non-spatial query field are not in index columns included in the composite spatial index of the database table, querying from the composite spatial index of the database table according to the query condition to find an alternate record that satisfies the query condition, and further querying back to the database table according to a primary key of the alternate record to obtain a complete row record that satisfies the query condition.
11. Querying the composite spatial index of the database table using the covering index scan according to the query condition includes: determining, according to the spatial query field, whether the spatial query field is a spatial field of the composite spatial index of the database table being queried; in response to 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 being queried, querying the composite spatial index using the covering index scan according to a length condition included in prefix information of the spatial query field; or 11. The method of claim 10, further comprising: in response to determining, according to the spatial query field, that the spatial query field is not a spatial field of the composite spatial index of the queried database table, querying the composite spatial index of the database table using the covering index scan.
12. querying the composite spatial index using the covering index scan according to the length condition contained in prefix information of the spatial query field; obtaining 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 satisfies the length condition; in response to determining that the length of the row record of the composite spatial index satisfies the length condition, using the row record as a query result of the covering index scan; 12. The method of claim 11, further comprising: in response to determining that the length of the row record of the composite spatial index does not satisfy the length condition, querying the database table according to primary key information.
13. obtaining the query results from the alternative records according to the spatial query field of the query condition and satisfying the query condition; performing spatial calculations on data of alternate row records and retrieving from the alternate row records those row records that match the spatial query field according to the calculation results; and using the row records that match the spatial query field as the query results that satisfy the query condition.
14. The method of claim 9 , wherein the spatial query information of the query condition is a minimum bounding rectangle operation that includes the spatial query field.
15. an index column of the tree-structured spatial index includes the spatial field; 10. The method of claim 9, wherein non-leaf nodes of the tree-structured spatial index store a minimum bounding rectangle for retrieving the spatial data and a page ID for retrieving a next level page.
16. 1. A database index processing device, comprising: a database table determination unit configured to determine a database table for which a database index is to be created, the database table including a spatial field for storing spatial data; a filter condition obtaining unit configured to obtain a spatial filter condition for the database table, the spatial filter condition including a spatial field ID; an index generation unit configured to generate a tree-structured spatial index for the database table according to the spatial filter condition, wherein leaf nodes of the tree-structured spatial index store spatial data that satisfies the spatial filter condition and a primary key ID.
17. 1. A database query processing apparatus, comprising: a database table determining unit configured to determine a database table to which spatial data is queried, the database table including a spatial field for storing the spatial data and a non-spatial field; a query condition determination unit configured to obtain a query condition for the database table, the query condition including a spatial query field; an index obtaining unit configured to obtain a tree-structured spatial index of the database table, wherein leaf nodes of the tree-structured spatial index store the spatial data; a query unit configured to query the tree-structured spatial index according to the query condition to obtain a query result; Querying the tree-structured spatial index to obtain the query results, obtaining 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; responsive to determining that the spatial field matches a spatial field ID of an index column of the tree-structured spatial index, querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain a query result that satisfies 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 in the database table that matches the query condition, and obtaining a query result that satisfies the query condition according to the spatial query field of the query condition and from the alternative record; 13. An apparatus comprising:
18. A memory and a processor, The memory is configured to store computer-executable commands, and the processor executes the computer-executable commands to determining a database table for which a database index is to be created, the database table including a spatial field for storing spatial data; obtaining a spatial filter condition for the database table, the spatial filter condition including a spatial field ID; generating a tree-structured spatial index for the database table in accordance with the spatial filter condition, wherein leaf nodes of the tree-structured spatial index store spatial data that satisfies the spatial filter condition, and a primary key ID.
19. A memory and a processor, The memory is configured to store computer-executable commands, and the processor executes the computer-executable commands to determining a database table from which spatial data is queried, the database table including a spatial field for storing the spatial data and a non-spatial field; obtaining a query condition for the database table, the query condition including a spatial query field; obtaining a tree-structured spatial index for the database table, the leaf nodes of the tree-structured spatial index storing spatial data; Querying the tree-structured spatial index according to the query condition to obtain a query result; [0023] The method is configured to perform operations including: Querying the tree-structured spatial index to obtain the query results, obtaining 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; responsive to determining that the spatial field matches a spatial field ID of an index column of the tree-structured spatial index, querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain a query result that satisfies 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 in the database table that matches the query condition, and obtaining a query result that satisfies the query condition according to the spatial query field of the query condition and from the alternative record; 2. An electronic device comprising:
20. A storage device having stored commands, the commands comprising: determining a database table for which a database index is to be created, the database table including a spatial field for storing spatial data; obtaining a spatial filter condition for the database table, the spatial filter condition including a spatial field ID; a storage device executable by a processor to cause the processor to perform operations including: generating a tree-structured spatial index for the database table in accordance with the spatial filter condition, wherein leaf nodes of the tree-structured spatial index store spatial data that satisfies the spatial filter condition, and a primary key ID.
21. A storage device having stored commands, the commands comprising: determining a database table from which spatial data is queried, the database table including a spatial field for storing the spatial data and a non-spatial field; obtaining a query condition for the database table, the query condition including a spatial query field; obtaining a tree-structured spatial index for the database table, the leaf nodes of the tree-structured spatial index storing spatial data; Querying the tree-structured spatial index according to the query condition to obtain a query result; and a processor executable to cause the processor to perform operations including: Querying the tree-structured spatial index to obtain the query results, obtaining 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; responsive to determining that the spatial field matches a spatial field ID of an index column of the tree-structured spatial index, querying the composite spatial index of the database table according to the spatial query field of the query condition to obtain a query result that satisfies 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 in the database table that matches the query condition, and obtaining a query result that satisfies the query condition according to the spatial query field of the query condition and from the alternative record; A storage device, including
Citation Information
Patent Citations
Data processing method, device, and its processing program
JP2007233658A
Space extraction device, extraction method for the same, and program
JP2010182097A
Region retrieval method, region retrieval program, and information processing unit
JP2013152531A
Information processor, information processing method, and program
JP2015055914A
