Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/tree/master/ext/rtree # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / rtree` `5909e4f` Have the rtree code catch SQLITE_TOOBIG and other errors in sqlite3_bind_blob(). Report [bugs:/info/2026-11-03T18:57:10Z | 2026-11-03T18:57:10Z]. dan committed 2026-11-09 ``` .. util/ README 4205 geopoly.c 54326 rtree.c 145179 rtree.h 776 rtree1.test 37605 rtree2.test 4033 rtree3.test 6983 rtree4.test 7645 rtree5.test 2165 rtree6.test 5160 rtree7.test 1809 rtree8.test 5964 rtree9.test 4348 rtreeA.test 8128 rtreeB.test 2309 rtreeC.test 9115 rtreeD.test 1433 rtreeE.test 5386 rtreeF.test 2326 rtreeG.test 1571 rtreeH.test 4087 rtreeI.test 3032 rtreeJ.test 5788 rtree_perf.tcl 1717 rtree_util.tcl 5409 rtreecheck.test 5429 rtreecirc.test 1536 rtreeconnect.test 1293 rtreedoc.test 54555 rtreedoc2.test 10233 rtreedoc3.test 8427 rtreefuzz001.test 85730 sqlite3rtree.h 4141 test_rtreedoc.c 9849 tkt3363.test 1141 viewrtree.tcl 5471 visual01.txt 22225 ``` README ``` This directory contains an SQLite extension that implements a virtual table type that allows users to create, query and manipulate r-tree[1] data structures inside of SQLite databases. Users create, populate and query r-tree structures using ordinary SQL statements. 1. SQL Interface 1.1 Table Creation 1.2 Data Manipulation 1.3 Data Querying 1.4 Introspection and Analysis 2. Compilation and Deployment 3. References 1. SQL INTERFACE 1.1 Table Creation. All r-tree virtual tables have an odd number of columns between 3 and 11. Unlike regular SQLite tables, r-tree tables are strongly typed. The leftmost column is always the primary key and contains 64-bit integer values. Each subsequent column contains a 32-bit real value. For each pair of real values, the first (leftmost) must be less than or equal to the second. R-tree tables may be constructed using the following syntax: CREATE VIRTUAL TABLE USING rtree() For example: CREATE VIRTUAL TABLE boxes USING rtree(boxno, xmin, xmax, ymin, ymax); INSERT INTO boxes VALUES(1, 1.0, 3.0, 2.0, 4.0); Constructing a virtual r-tree table creates the following three real tables in the database to store the data structure: _node _rowid _parent Dropping or modifying the contents of these tables directly will corrupt the r-tree structure. To delete an r-tree from a database, use a regular DROP TABLE statement: DROP TABLE ; Dropping the main r-tree table automatically drops the automatically created tables. 1.2 Data Manipulation (INSERT, UPDATE, DELETE). The usual INSERT, UPDATE or DELETE syntax is used to manipulate data stored in an r-tree table. Please note the following: * Inserting a NULL value into the primary key column has the same effect as inserting a NULL into an INTEGER PRIMARY KEY column of a regular table. The system automatically assigns an unused integer key value to the new record. Usually, this is one greater than the largest primary key value currently present in the table. * Attempting to insert a duplicate primary key value fails with an SQLITE_CONSTRAINT error. * Attempting to insert or modify a record such that the value stored in the (N*2)th column is greater than that stored in the (N*2+1)th column fails with an SQLITE_CONSTRAINT error. * When a record is inserted, values are always converted to the required type (64-bit integer or 32-bit real) as if they were part of an SQL CAST expression. Non-numeric strings are converted to zero. 1.3 Queries. R-tree tables may be queried using all of the same SQL syntax supported by regular tables. However, some query patterns are more efficient than others. R-trees support fast lookup by primary key value (O(logN), like regular tables). Any combination of equality and range (<, <=, >, >=) constraints on spatial data columns may be used to optimize other queries. This is the key advantage to using r-tree tables instead of creating indices on regular tables. 1.4 Introspection and Analysis. TODO: Describe rtreenode() and rtreedepth() functions. 2. COMPILATION AND USAGE The easiest way to compile and use the RTREE extension is to build and use it as a dynamically loadable SQLite extension. To do this using gcc on *nix: gcc -shared rtree.c -o libSqliteRtree.so You may need to add "-I" flags so that gcc can find sqlite3ext.h and sqlite3.h. The resulting shared lib, libSqliteRtree.so, may be loaded into sqlite in the same way as any other dynamicly loadable extension. 3. REFERENCES [1] Atonin Guttman, "R-trees - A Dynamic Index Structure For Spatial Searching", University of California Berkeley, 1984. [2] Norbert Beckmann, Hans-Peter Kriegel, Ralf Schneider, Bernhard Seeger, "The R*-tree: An Efficient and Robust Access Method for Points and Rectangles", Universitaet Bremen, 1990. ```