Lines Matching defs:pRtree

191490 ** variable pRtree points to the Rtree structure associated with the
191497 (pRtree->eCoordType==RTREE_COORD_REAL32) ? \
191786 static void nodeZero(Rtree *pRtree, RtreeNode *p){
191787 memset(&p->zData[2], 0, pRtree->iNodeSize-2);
191803 static RtreeNode *nodeHashLookup(Rtree *pRtree, i64 iNode){
191805 for(p=pRtree->aHash[nodeHash(iNode)]; p && p->iNode!=iNode; p=p->pNext);
191812 static void nodeHashInsert(Rtree *pRtree, RtreeNode *pNode){
191816 pNode->pNext = pRtree->aHash[iHash];
191817 pRtree->aHash[iHash] = pNode;
191823 static void nodeHashDelete(Rtree *pRtree, RtreeNode *pNode){
191826 pp = &pRtree->aHash[nodeHash(pNode->iNode)];
191839 static RtreeNode *nodeNew(Rtree *pRtree, RtreeNode *pParent){
191841 pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode) + pRtree->iNodeSize);
191843 memset(pNode, 0, sizeof(RtreeNode) + pRtree->iNodeSize);
191846 pRtree->nNodeRef++;
191857 static void nodeBlobReset(Rtree *pRtree){
191858 if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){
191859 sqlite3_blob *pBlob = pRtree->pNodeBlob;
191860 pRtree->pNodeBlob = 0;
191881 Rtree *pRtree, /* R-tree structure */
191892 if( (pNode = nodeHashLookup(pRtree, iNode))!=0 ){
191895 RTREE_IS_CORRUPT(pRtree);
191901 RTREE_IS_CORRUPT(pRtree);
191909 if( pRtree->pNodeBlob ){
191910 sqlite3_blob *pBlob = pRtree->pNodeBlob;
191911 pRtree->pNodeBlob = 0;
191913 pRtree->pNodeBlob = pBlob;
191915 nodeBlobReset(pRtree);
191919 if( pRtree->pNodeBlob==0 ){
191920 char *zTab = sqlite3_mprintf("%s_node", pRtree->zName);
191922 rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, zTab, "data", iNode, 0,
191923 &pRtree->pNodeBlob);
191927 nodeBlobReset(pRtree);
191933 RTREE_IS_CORRUPT(pRtree);
191935 }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){
191936 pNode = (RtreeNode *)sqlite3_malloc64(sizeof(RtreeNode)+pRtree->iNodeSize);
191943 pRtree->nNodeRef++;
191947 rc = sqlite3_blob_read(pRtree->pNodeBlob, pNode->zData,
191948 pRtree->iNodeSize, 0);
191952 /* If the root node was just loaded, set pRtree->iDepth to the height
191959 pRtree->iDepth = readInt16(pNode->zData);
191960 if( pRtree->iDepth>RTREE_MAX_DEPTH ){
191962 RTREE_IS_CORRUPT(pRtree);
191971 if( NCELL(pNode)>((pRtree->iNodeSize-4)/pRtree->nBytesPerCell) ){
191973 RTREE_IS_CORRUPT(pRtree);
191980 nodeHashInsert(pRtree, pNode);
191983 RTREE_IS_CORRUPT(pRtree);
191988 pRtree->nNodeRef--;
192001 Rtree *pRtree, /* The overall R-Tree */
192007 u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell];
192009 for(ii=0; ii<pRtree->nDim2; ii++){
192018 static void nodeDeleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell){
192019 u8 *pDst = &pNode->zData[4 + pRtree->nBytesPerCell*iCell];
192020 u8 *pSrc = &pDst[pRtree->nBytesPerCell];
192021 int nByte = (NCELL(pNode) - iCell - 1) * pRtree->nBytesPerCell;
192034 Rtree *pRtree, /* The overall R-Tree */
192041 nMaxCell = (pRtree->iNodeSize-4)/pRtree->nBytesPerCell;
192046 nodeOverwriteCell(pRtree, pNode, pCell, nCell);
192057 static int nodeWrite(Rtree *pRtree, RtreeNode *pNode){
192060 sqlite3_stmt *p = pRtree->pWriteNode;
192066 sqlite3_bind_blob(p, 2, pNode->zData, pRtree->iNodeSize, SQLITE_STATIC);
192072 pNode->iNode = sqlite3_last_insert_rowid(pRtree->db);
192073 nodeHashInsert(pRtree, pNode);
192083 static int nodeRelease(Rtree *pRtree, RtreeNode *pNode){
192087 assert( pRtree->nNodeRef>0 );
192090 pRtree->nNodeRef--;
192092 pRtree->iDepth = -1;
192095 rc = nodeRelease(pRtree, pNode->pParent);
192098 rc = nodeWrite(pRtree, pNode);
192100 nodeHashDelete(pRtree, pNode);
192113 Rtree *pRtree, /* The overall R-Tree */
192118 return readInt64(&pNode->zData[4 + pRtree->nBytesPerCell*iCell]);
192125 Rtree *pRtree, /* The overall R-Tree */
192131 readCoord(&pNode->zData[12 + pRtree->nBytesPerCell*iCell + 4*iCoord], pCoord);
192139 Rtree *pRtree, /* The overall R-Tree */
192147 pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell);
192148 pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell);
192155 }while( ii<pRtree->nDim2 );
192195 static void rtreeReference(Rtree *pRtree){
192196 pRtree->nBusy++;
192203 static void rtreeRelease(Rtree *pRtree){
192204 pRtree->nBusy--;
192205 if( pRtree->nBusy==0 ){
192206 pRtree->inWrTrans = 0;
192207 assert( pRtree->nCursor==0 );
192208 nodeBlobReset(pRtree);
192209 assert( pRtree->nNodeRef==0 || pRtree->bCorrupt );
192210 sqlite3_finalize(pRtree->pWriteNode);
192211 sqlite3_finalize(pRtree->pDeleteNode);
192212 sqlite3_finalize(pRtree->pReadRowid);
192213 sqlite3_finalize(pRtree->pWriteRowid);
192214 sqlite3_finalize(pRtree->pDeleteRowid);
192215 sqlite3_finalize(pRtree->pReadParent);
192216 sqlite3_finalize(pRtree->pWriteParent);
192217 sqlite3_finalize(pRtree->pDeleteParent);
192218 sqlite3_finalize(pRtree->pWriteAux);
192219 sqlite3_free(pRtree->zReadAuxSql);
192220 sqlite3_free(pRtree);
192236 Rtree *pRtree = (Rtree *)pVtab;
192242 pRtree->zDb, pRtree->zName,
192243 pRtree->zDb, pRtree->zName,
192244 pRtree->zDb, pRtree->zName
192249 nodeBlobReset(pRtree);
192250 rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0);
192254 rtreeRelease(pRtree);
192265 Rtree *pRtree = (Rtree *)pVTab;
192273 pRtree->nCursor++;
192285 Rtree *pRtree = (Rtree *)(pCsr->base.pVtab);
192300 for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]);
192304 pCsr->base.pVtab = (sqlite3_vtab*)pRtree;
192313 Rtree *pRtree = (Rtree *)(cur->pVtab);
192315 assert( pRtree->nCursor>0 );
192319 pRtree->nCursor--;
192320 nodeBlobReset(pRtree);
192540 Rtree *pRtree,
192549 if( nodeGetRowid(pRtree, pNode, ii)==iRowid ){
192554 RTREE_IS_CORRUPT(pRtree);
192562 static int nodeParentIndex(Rtree *pRtree, RtreeNode *pNode, int *piIndex){
192565 return nodeRowidIndex(pRtree, pParent, pNode->iNode, piIndex);
192791 Rtree *pRtree = RTREE_OF_CURSOR(pCur);
192801 eInt = pRtree->eCoordType==RTREE_COORD_INT32;
192808 pCellData = pNode->zData + (4+pRtree->nBytesPerCell*p->iCell);
192825 pCellData += pRtree->nBytesPerCell;
192836 RTREE_IS_CORRUPT(pRtree);
192903 Rtree *pRtree = (Rtree *)cur->pVtab;
192913 sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell));
192914 }else if( i<=pRtree->nDim2 ){
192915 nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c);
192917 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
192922 assert( pRtree->eCoordType==RTREE_COORD_INT32 );
192928 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
192933 nodeGetRowid(pRtree, pNode, p->iCell));
192944 sqlite3_column_value(pCsr->pReadAux, i - pRtree->nDim2 + 1));
192957 Rtree *pRtree, /* RTree to search */
192964 sqlite3_bind_int64(pRtree->pReadRowid, 1, iRowid);
192965 if( sqlite3_step(pRtree->pReadRowid)==SQLITE_ROW ){
192966 i64 iNode = sqlite3_column_int64(pRtree->pReadRowid, 0);
192968 rc = nodeAcquire(pRtree, iNode, 0, ppLeaf);
192969 sqlite3_reset(pRtree->pReadRowid);
192971 rc = sqlite3_reset(pRtree->pReadRowid);
193017 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
193024 rtreeReference(pRtree);
193040 rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
193051 rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
193061 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
193069 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
193086 p->pInfo->nCoord = pRtree->nDim2;
193088 p->pInfo->mxLevel = pRtree->iDepth + 1;
193110 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
193123 nodeRelease(pRtree, pRoot);
193124 rtreeRelease(pRtree);
193163 Rtree *pRtree = (Rtree*)tab;
193213 && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2)
193241 nRow = pRtree->nRowEst >> (iIdx/2);
193251 static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){
193253 assert( pRtree->nDim>=1 && pRtree->nDim<=5 );
193255 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
193256 switch( pRtree->nDim ){
193266 switch( pRtree->nDim ){
193281 static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){
193283 int ii = pRtree->nDim2 - 2;
193294 static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
193296 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
193301 }while( ii<pRtree->nDim2 );
193307 }while( ii<pRtree->nDim2 );
193315 static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){
193317 int isInt = (pRtree->eCoordType==RTREE_COORD_INT32);
193318 for(ii=0; ii<pRtree->nDim2; ii+=2){
193333 static RtreeDValue cellGrowth(Rtree *pRtree, RtreeCell *p, RtreeCell *pCell){
193337 area = cellArea(pRtree, &cell);
193338 cellUnion(pRtree, &cell, pCell);
193339 return (cellArea(pRtree, &cell)-area);
193343 Rtree *pRtree,
193353 for(jj=0; jj<pRtree->nDim2; jj+=2){
193375 Rtree *pRtree, /* Rtree table */
193383 rc = nodeAcquire(pRtree, 1, 0, &pNode);
193385 for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
193406 nodeGetCell(pRtree, pNode, iCell, &cell);
193407 growth = cellGrowth(pRtree, &cell, pCell);
193408 area = cellArea(pRtree, &cell);
193420 rc = nodeAcquire(pRtree, iBest, pNode, &pChild);
193421 nodeRelease(pRtree, pNode);
193435 Rtree *pRtree, /* Rtree table */
193446 if( (++cnt)>1000 || nodeParentIndex(pRtree, p, &iCell) ){
193447 RTREE_IS_CORRUPT(pRtree);
193451 nodeGetCell(pRtree, pParent, iCell, &cell);
193452 if( !cellContains(pRtree, &cell, pCell) ){
193453 cellUnion(pRtree, &cell, pCell);
193454 nodeOverwriteCell(pRtree, pParent, &cell, iCell);
193465 static int rowidWrite(Rtree *pRtree, sqlite3_int64 iRowid, sqlite3_int64 iNode){
193466 sqlite3_bind_int64(pRtree->pWriteRowid, 1, iRowid);
193467 sqlite3_bind_int64(pRtree->pWriteRowid, 2, iNode);
193468 sqlite3_step(pRtree->pWriteRowid);
193469 return sqlite3_reset(pRtree->pWriteRowid);
193475 static int parentWrite(Rtree *pRtree, sqlite3_int64 iNode, sqlite3_int64 iPar){
193476 sqlite3_bind_int64(pRtree->pWriteParent, 1, iNode);
193477 sqlite3_bind_int64(pRtree->pWriteParent, 2, iPar);
193478 sqlite3_step(pRtree->pWriteParent);
193479 return sqlite3_reset(pRtree->pWriteParent);
193569 Rtree *pRtree,
193586 SortByDimension(pRtree, aLeft, nLeft, iDim, aCell, aSpare);
193587 SortByDimension(pRtree, aRight, nRight, iDim, aCell, aSpare);
193628 Rtree *pRtree,
193644 sqlite3_int64 nByte = (pRtree->nDim+1)*(sizeof(int*)+nCell*sizeof(int));
193651 aSpare = &((int *)&aaSorted[pRtree->nDim])[pRtree->nDim*nCell];
193653 for(ii=0; ii<pRtree->nDim; ii++){
193655 aaSorted[ii] = &((int *)&aaSorted[pRtree->nDim])[ii*nCell];
193659 SortByDimension(pRtree, aaSorted[ii], nCell, ii, aCell, aSpare);
193662 for(ii=0; ii<pRtree->nDim; ii++){
193670 nLeft=RTREE_MINCELLS(pRtree);
193671 nLeft<=(nCell-RTREE_MINCELLS(pRtree));
193684 cellUnion(pRtree, &left, &aCell[aaSorted[ii][kk]]);
193686 cellUnion(pRtree, &right, &aCell[aaSorted[ii][kk]]);
193689 margin += cellMargin(pRtree, &left);
193690 margin += cellMargin(pRtree, &right);
193691 overlap = cellOverlap(pRtree, &left, &right, 1);
193692 area = cellArea(pRtree, &left) + cellArea(pRtree, &right);
193693 if( (nLeft==RTREE_MINCELLS(pRtree))
193716 nodeInsertCell(pRtree, pTarget, pCell);
193717 cellUnion(pRtree, pBbox, pCell);
193726 Rtree *pRtree,
193734 RtreeNode *pChild = nodeHashLookup(pRtree, iRowid);
193736 nodeRelease(pRtree, pChild->pParent);
193741 return xSetMapping(pRtree, iRowid, pNode->iNode);
193745 Rtree *pRtree,
193775 nodeGetCell(pRtree, pNode, i, &aCell[i]);
193777 nodeZero(pRtree, pNode);
193782 pRight = nodeNew(pRtree, pNode);
193783 pLeft = nodeNew(pRtree, pNode);
193784 pRtree->iDepth++;
193786 writeInt16(pNode->zData, pRtree->iDepth);
193789 pRight = nodeNew(pRtree, pLeft->pParent);
193798 memset(pLeft->zData, 0, pRtree->iNodeSize);
193799 memset(pRight->zData, 0, pRtree->iNodeSize);
193801 rc = splitNodeStartree(pRtree, aCell, nCell, pLeft, pRight,
193812 if( SQLITE_OK!=(rc = nodeWrite(pRtree, pRight))
193813 || (0==pLeft->iNode && SQLITE_OK!=(rc = nodeWrite(pRtree, pLeft)))
193822 rc = rtreeInsertCell(pRtree, pLeft->pParent, &leftbbox, iHeight+1);
193829 rc = nodeParentIndex(pRtree, pLeft, &iCell);
193831 nodeOverwriteCell(pRtree, pParent, &leftbbox, iCell);
193832 rc = AdjustTree(pRtree, pParent, &leftbbox);
193838 if( (rc = rtreeInsertCell(pRtree, pRight->pParent, &rightbbox, iHeight+1)) ){
193843 i64 iRowid = nodeGetRowid(pRtree, pRight, i);
193844 rc = updateMapping(pRtree, iRowid, pRight, iHeight);
193854 i64 iRowid = nodeGetRowid(pRtree, pLeft, i);
193855 rc = updateMapping(pRtree, iRowid, pLeft, iHeight);
193861 rc = updateMapping(pRtree, pCell->iRowid, pLeft, iHeight);
193865 rc = nodeRelease(pRtree, pRight);
193869 rc = nodeRelease(pRtree, pLeft);
193874 nodeRelease(pRtree, pRight);
193875 nodeRelease(pRtree, pLeft);
193891 static int fixLeafParent(Rtree *pRtree, RtreeNode *pLeaf){
193896 sqlite3_bind_int64(pRtree->pReadParent, 1, pChild->iNode);
193897 rc = sqlite3_step(pRtree->pReadParent);
193907 iNode = sqlite3_column_int64(pRtree->pReadParent, 0);
193910 rc2 = nodeAcquire(pRtree, iNode, 0, &pChild->pParent);
193913 rc = sqlite3_reset(pRtree->pReadParent);
193916 RTREE_IS_CORRUPT(pRtree);
193926 static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){
193935 rc = nodeParentIndex(pRtree, pNode, &iCell);
193939 rc = deleteCell(pRtree, pParent, iCell, iHeight+1);
193941 rc2 = nodeRelease(pRtree, pParent);
193950 sqlite3_bind_int64(pRtree->pDeleteNode, 1, pNode->iNode);
193951 sqlite3_step(pRtree->pDeleteNode);
193952 if( SQLITE_OK!=(rc = sqlite3_reset(pRtree->pDeleteNode)) ){
193957 sqlite3_bind_int64(pRtree->pDeleteParent, 1, pNode->iNode);
193958 sqlite3_step(pRtree->pDeleteParent);
193959 if( SQLITE_OK!=(rc = sqlite3_reset(pRtree->pDeleteParent)) ){
193966 nodeHashDelete(pRtree, pNode);
193968 pNode->pNext = pRtree->pDeleted;
193970 pRtree->pDeleted = pNode;
193975 static int fixBoundingBox(Rtree *pRtree, RtreeNode *pNode){
193982 nodeGetCell(pRtree, pNode, 0, &box);
193985 nodeGetCell(pRtree, pNode, ii, &cell);
193986 cellUnion(pRtree, &box, &cell);
193989 rc = nodeParentIndex(pRtree, pNode, &ii);
193991 nodeOverwriteCell(pRtree, pParent, &box, ii);
193992 rc = fixBoundingBox(pRtree, pParent);
194002 static int deleteCell(Rtree *pRtree, RtreeNode *pNode, int iCell, int iHeight){
194006 if( SQLITE_OK!=(rc = fixLeafParent(pRtree, pNode)) ){
194013 nodeDeleteCell(pRtree, pNode, iCell);
194023 if( NCELL(pNode)<RTREE_MINCELLS(pRtree) ){
194024 rc = removeNode(pRtree, pNode, iHeight);
194026 rc = fixBoundingBox(pRtree, pNode);
194034 Rtree *pRtree,
194075 nodeGetCell(pRtree, pNode, ii, &aCell[ii]);
194078 for(iDim=0; iDim<pRtree->nDim; iDim++){
194083 for(iDim=0; iDim<pRtree->nDim; iDim++){
194089 for(iDim=0; iDim<pRtree->nDim; iDim++){
194097 nodeZero(pRtree, pNode);
194099 for(ii=0; rc==SQLITE_OK && ii<(nCell-(RTREE_MINCELLS(pRtree)+1)); ii++){
194101 nodeInsertCell(pRtree, pNode, p);
194104 rc = rowidWrite(pRtree, p->iRowid, pNode->iNode);
194106 rc = parentWrite(pRtree, p->iRowid, pNode->iNode);
194111 rc = fixBoundingBox(pRtree, pNode);
194119 rc = ChooseLeaf(pRtree, p, iHeight, &pInsert);
194122 rc = rtreeInsertCell(pRtree, pInsert, p, iHeight);
194123 rc2 = nodeRelease(pRtree, pInsert);
194139 Rtree *pRtree,
194146 RtreeNode *pChild = nodeHashLookup(pRtree, pCell->iRowid);
194148 nodeRelease(pRtree, pChild->pParent);
194153 if( nodeInsertCell(pRtree, pNode, pCell) ){
194154 if( iHeight<=pRtree->iReinsertHeight || pNode->iNode==1){
194155 rc = SplitNode(pRtree, pNode, pCell, iHeight);
194157 pRtree->iReinsertHeight = iHeight;
194158 rc = Reinsert(pRtree, pNode, pCell, iHeight);
194161 rc = AdjustTree(pRtree, pNode, pCell);
194164 rc = rowidWrite(pRtree, pCell->iRowid, pNode->iNode);
194166 rc = parentWrite(pRtree, pCell->iRowid, pNode->iNode);
194173 static int reinsertNodeContent(Rtree *pRtree, RtreeNode *pNode){
194181 nodeGetCell(pRtree, pNode, ii, &cell);
194186 rc = ChooseLeaf(pRtree, &cell, (int)pNode->iNode, &pInsert);
194189 rc = rtreeInsertCell(pRtree, pInsert, &cell, (int)pNode->iNode);
194190 rc2 = nodeRelease(pRtree, pInsert);
194202 static int rtreeNewRowid(Rtree *pRtree, i64 *piRowid){
194204 sqlite3_bind_null(pRtree->pWriteRowid, 1);
194205 sqlite3_bind_null(pRtree->pWriteRowid, 2);
194206 sqlite3_step(pRtree->pWriteRowid);
194207 rc = sqlite3_reset(pRtree->pWriteRowid);
194208 *piRowid = sqlite3_last_insert_rowid(pRtree->db);
194215 static int rtreeDeleteRowid(Rtree *pRtree, sqlite3_int64 iDelete){
194223 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
194229 rc = findLeafNode(pRtree, iDelete, &pLeaf, 0);
194239 rc = nodeRowidIndex(pRtree, pLeaf, iDelete, &iCell);
194241 rc = deleteCell(pRtree, pLeaf, iCell, 0);
194243 rc2 = nodeRelease(pRtree, pLeaf);
194251 sqlite3_bind_int64(pRtree->pDeleteRowid, 1, iDelete);
194252 sqlite3_step(pRtree->pDeleteRowid);
194253 rc = sqlite3_reset(pRtree->pDeleteRowid);
194264 if( rc==SQLITE_OK && pRtree->iDepth>0 && NCELL(pRoot)==1 ){
194267 i64 iChild = nodeGetRowid(pRtree, pRoot, 0);
194268 rc = nodeAcquire(pRtree, iChild, pRoot, &pChild);
194270 rc = removeNode(pRtree, pChild, pRtree->iDepth-1);
194272 rc2 = nodeRelease(pRtree, pChild);
194275 pRtree->iDepth--;
194276 writeInt16(pRoot->zData, pRtree->iDepth);
194282 for(pLeaf=pRtree->pDeleted; pLeaf; pLeaf=pRtree->pDeleted){
194284 rc = reinsertNodeContent(pRtree, pLeaf);
194286 pRtree->pDeleted = pLeaf->pNext;
194287 pRtree->nNodeRef--;
194293 rc = nodeRelease(pRtree, pRoot);
194295 nodeRelease(pRtree, pRoot);
194333 ** (at pRtree->base.zErrMsg) to an appropriate value and returns
194343 static int rtreeConstraintError(Rtree *pRtree, int iCol){
194349 zSql = sqlite3_mprintf("SELECT * FROM %Q.%Q", pRtree->zDb, pRtree->zName);
194351 rc = sqlite3_prepare_v2(pRtree->db, zSql, -1, &pStmt, 0);
194360 pRtree->base.zErrMsg = sqlite3_mprintf(
194361 "UNIQUE constraint failed: %s.%s", pRtree->zName, zCol
194366 pRtree->base.zErrMsg = sqlite3_mprintf(
194367 "rtree constraint failed: %s.(%s<=%s)", pRtree->zName, zCol1, zCol2
194387 Rtree *pRtree = (Rtree *)pVtab;
194392 if( pRtree->nNodeRef ){
194398 rtreeReference(pRtree);
194418 if( nn > pRtree->nDim2 ) nn = pRtree->nDim2;
194429 if( pRtree->eCoordType==RTREE_COORD_REAL32 ){
194434 rc = rtreeConstraintError(pRtree, ii+1);
194445 rc = rtreeConstraintError(pRtree, ii+1);
194459 sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
194460 steprc = sqlite3_step(pRtree->pReadRowid);
194461 rc = sqlite3_reset(pRtree->pReadRowid);
194463 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
194464 rc = rtreeDeleteRowid(pRtree, cell.iRowid);
194466 rc = rtreeConstraintError(pRtree, 0);
194480 rc = rtreeDeleteRowid(pRtree, sqlite3_value_int64(aData[0]));
194493 rc = rtreeNewRowid(pRtree, &cell.iRowid);
194498 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
194502 pRtree->iReinsertHeight = -1;
194503 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
194504 rc2 = nodeRelease(pRtree, pLeaf);
194509 if( rc==SQLITE_OK && pRtree->nAux ){
194510 sqlite3_stmt *pUp = pRtree->pWriteAux;
194513 for(jj=0; jj<pRtree->nAux; jj++){
194514 sqlite3_bind_value(pUp, jj+2, aData[pRtree->nDim2+3+jj]);
194522 rtreeRelease(pRtree);
194530 Rtree *pRtree = (Rtree *)pVtab;
194531 assert( pRtree->inWrTrans==0 );
194532 pRtree->inWrTrans++;
194541 Rtree *pRtree = (Rtree *)pVtab;
194542 pRtree->inWrTrans = 0;
194543 nodeBlobReset(pRtree);
194551 Rtree *pRtree = (Rtree *)pVtab;
194557 , pRtree->zDb, pRtree->zName, zNewName
194558 , pRtree->zDb, pRtree->zName, zNewName
194559 , pRtree->zDb, pRtree->zName, zNewName
194562 nodeBlobReset(pRtree);
194563 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
194584 Rtree *pRtree = (Rtree *)pVtab;
194585 u8 iwt = pRtree->inWrTrans;
194587 pRtree->inWrTrans = 0;
194588 nodeBlobReset(pRtree);
194589 pRtree->inWrTrans = iwt;
194594 ** This function populates the pRtree->nRowEst variable with an estimate
194598 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
194606 db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
194609 pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
194612 zSql = sqlite3_mprintf(zFmt, pRtree->zDb, pRtree->zName);
194626 pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
194628 pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
194681 Rtree *pRtree,
194709 pRtree->db = db;
194718 for(ii=0; ii<pRtree->nAux; ii++){
194729 zDb, zPrefix, pRtree->iNodeSize);
194741 appStmt[0] = &pRtree->pWriteNode;
194742 appStmt[1] = &pRtree->pDeleteNode;
194743 appStmt[2] = &pRtree->pReadRowid;
194744 appStmt[3] = &pRtree->pWriteRowid;
194745 appStmt[4] = &pRtree->pDeleteRowid;
194746 appStmt[5] = &pRtree->pReadParent;
194747 appStmt[6] = &pRtree->pWriteParent;
194748 appStmt[7] = &pRtree->pDeleteParent;
194750 rc = rtreeQueryStat1(db, pRtree);
194754 if( i!=3 || pRtree->nAux==0 ){
194770 if( pRtree->nAux ){
194771 pRtree->zReadAuxSql = sqlite3_mprintf(
194774 if( pRtree->zReadAuxSql==0 ){
194781 for(ii=0; ii<pRtree->nAux; ii++){
194783 if( ii<pRtree->nAuxNotNull ){
194794 rc = sqlite3_prepare_v3(db, zSql, -1, f, &pRtree->pWriteAux, 0);
194828 ** to. If successful, pRtree->iNodeSize is populated and SQLITE_OK returned.
194842 Rtree *pRtree, /* Rtree handle */
194850 zSql = sqlite3_mprintf("PRAGMA %Q.page_size", pRtree->zDb);
194853 pRtree->iNodeSize = iPageSize-64;
194854 if( (4+pRtree->nBytesPerCell*RTREE_MAXCELLS)<pRtree->iNodeSize ){
194855 pRtree->iNodeSize = 4+pRtree->nBytesPerCell*RTREE_MAXCELLS;
194863 pRtree->zDb, pRtree->zName
194865 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
194868 }else if( pRtree->iNodeSize<(512-64) ){
194870 RTREE_IS_CORRUPT(pRtree);
194872 pRtree->zName);
194906 Rtree *pRtree;
194934 pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
194935 if( !pRtree ){
194938 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
194939 pRtree->nBusy = 1;
194940 pRtree->base.pModule = &rtreeModule;
194941 pRtree->zDb = (char *)&pRtree[1];
194942 pRtree->zName = &pRtree->zDb[nDb+1];
194943 pRtree->eCoordType = (u8)eCoordType;
194944 memcpy(pRtree->zDb, argv[1], nDb);
194945 memcpy(pRtree->zName, argv[2], nName);
194958 pRtree->nAux++;
194960 }else if( pRtree->nAux>0 ){
194964 pRtree->nDim2++;
194981 pRtree->nDim = pRtree->nDim2/2;
194982 if( pRtree->nDim<1 ){
194984 }else if( pRtree->nDim2>RTREE_MAX_DIMENSIONS*2 ){
194986 }else if( pRtree->nDim2 % 2 ){
194995 pRtree->nBytesPerCell = 8 + pRtree->nDim2*4;
194998 rc = getNodeSize(db, pRtree, isCreate, pzErr);
195000 rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate);
195006 *ppVtab = (sqlite3_vtab *)pRtree;
195012 assert( pRtree->nBusy==1 );
195013 rtreeRelease(pRtree);
196794 Rtree *pRtree;
196806 pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
196807 if( !pRtree ){
196810 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
196811 pRtree->nBusy = 1;
196812 pRtree->base.pModule = &rtreeModule;
196813 pRtree->zDb = (char *)&pRtree[1];
196814 pRtree->zName = &pRtree->zDb[nDb+1];
196815 pRtree->eCoordType = RTREE_COORD_REAL32;
196816 pRtree->nDim = 2;
196817 pRtree->nDim2 = 4;
196818 memcpy(pRtree->zDb, argv[1], nDb);
196819 memcpy(pRtree->zName, argv[2], nName);
196828 pRtree->nAux = 1; /* Add one for _shape */
196829 pRtree->nAuxNotNull = 1; /* The _shape column is always not-null */
196831 pRtree->nAux++;
196843 pRtree->nBytesPerCell = 8 + pRtree->nDim2*4;
196846 rc = getNodeSize(db, pRtree, isCreate, pzErr);
196848 rc = rtreeSqlInit(pRtree, db, argv[1], argv[2], isCreate);
196854 *ppVtab = (sqlite3_vtab *)pRtree;
196860 assert( pRtree->nBusy==1 );
196861 rtreeRelease(pRtree);
196911 Rtree *pRtree = (Rtree *)pVtabCursor->pVtab;
196917 rtreeReference(pRtree);
196929 rc = findLeafNode(pRtree, iRowid, &pLeaf, &iNode);
196936 rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell);
196946 rc = nodeAcquire(pRtree, 1, 0, &pRoot);
196961 memset(pCsr->anQueue, 0, sizeof(u32)*(pRtree->iDepth + 1));
197001 pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1));
197018 nodeRelease(pRtree, pRoot);
197019 rtreeRelease(pRtree);
197089 Rtree *pRtree = (Rtree *)cur->pVtab;
197098 if( i<=pRtree->nAux ){
197101 rc = sqlite3_prepare_v3(pRtree->db, pRtree->zReadAuxSql, -1, 0,
197106 nodeGetRowid(pRtree, pNode, p->iCell));
197149 Rtree *pRtree = (Rtree *)pVtab;
197158 if( pRtree->nNodeRef ){
197164 rtreeReference(pRtree);
197192 sqlite3_bind_int64(pRtree->pReadRowid, 1, cell.iRowid);
197193 steprc = sqlite3_step(pRtree->pReadRowid);
197194 rc = sqlite3_reset(pRtree->pReadRowid);
197196 if( sqlite3_vtab_on_conflict(pRtree->db)==SQLITE_REPLACE ){
197197 rc = rtreeDeleteRowid(pRtree, cell.iRowid);
197199 rc = rtreeConstraintError(pRtree, 0);
197210 rc = rtreeDeleteRowid(pRtree, oldRowid);
197221 rc = rtreeNewRowid(pRtree, &cell.iRowid);
197225 rc = ChooseLeaf(pRtree, &cell, 0, &pLeaf);
197229 pRtree->iReinsertHeight = -1;
197230 rc = rtreeInsertCell(pRtree, pLeaf, &cell, 0);
197231 rc2 = nodeRelease(pRtree, pLeaf);
197240 sqlite3_stmt *pUp = pRtree->pWriteAux;
197244 assert( pRtree->nAux>=1 );
197260 for(jj=1; jj<pRtree->nAux; jj++){
197271 rtreeRelease(pRtree);