1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

In the ChooseLeaf algorithm of RTREE, do an initial pass through the cells

of a node looking for solutions that involve no cell enlargement.  Only look
for the minimum cell enlargement if the enlargement is non-zero for all cells.
This results in a performance improvement by reducing the number of calls
to cellUnion().

FossilOrigin-Name: 59f0e239d19393190911ea3bd89b5a24be0d85d64ccf51906efc9537ad5d7298
This commit is contained in:
drh
2023-09-13 13:12:08 +00:00
parent 386e359044
commit cdae00b3e8
3 changed files with 41 additions and 24 deletions

View File

@ -2221,32 +2221,49 @@ static int ChooseLeaf(
for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
int iCell;
sqlite3_int64 iBest = 0;
int bFound = 0;
RtreeDValue fMinGrowth = RTREE_ZERO;
RtreeDValue fMinArea = RTREE_ZERO;
int nCell = NCELL(pNode);
RtreeNode *pChild = 0;
/* Select the child node which will be enlarged the least if pCell
** is inserted into it. Resolve ties by choosing the entry with
** the smallest area.
/* First check to see if there is are any cells in pNode that completely
** contains pCell. If two or more cells in pNode completely contain pCell
** then pick the smallest.
*/
for(iCell=0; iCell<nCell; iCell++){
RtreeCell cell;
RtreeDValue growth;
RtreeDValue area;
nodeGetCell(pRtree, pNode, iCell, &cell);
area = cellArea(pRtree, &cell);
cellUnion(pRtree, &cell, pCell);
growth = cellArea(pRtree, &cell)-area;
if( iCell==0
|| growth<fMinGrowth
|| (growth==fMinGrowth && area<fMinArea)
){
fMinGrowth = growth;
fMinArea = area;
iBest = cell.iRowid;
if( cellContains(pRtree, &cell, pCell) ){
RtreeDValue area = cellArea(pRtree, &cell);
if( bFound==0 || area<fMinArea ){
iBest = cell.iRowid;
fMinArea = area;
bFound = 1;
}
}
}
if( !bFound ){
/* No cells of pNode will completely contain pCell. So pick the
** cell of pNode that grows by the least amount when pCell is added.
** Break ties by selecting the smaller cell.
*/
for(iCell=0; iCell<nCell; iCell++){
RtreeCell cell;
RtreeDValue growth;
RtreeDValue area;
nodeGetCell(pRtree, pNode, iCell, &cell);
area = cellArea(pRtree, &cell);
cellUnion(pRtree, &cell, pCell);
growth = cellArea(pRtree, &cell)-area;
if( iCell==0
|| growth<fMinGrowth
|| (growth==fMinGrowth && area<fMinArea)
){
fMinGrowth = growth;
fMinArea = area;
iBest = cell.iRowid;
}
}
}