Documentation Source Text

Check-in [64af4ea91f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add documentation for the UNION virtual table.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 64af4ea91f78285b138c6b3a76ff7748e68eb3ffefca74ea624e12bd2bac9013
User & Date: drh 2017-07-21 19:12:49.846
Context
2017-07-21
19:32
Add the enhanced ability for date/time functions to be deterministic to the change log and to the "deterministic function" documentation. (check-in: e27224b526 user: drh tags: trunk)
19:12
Add documentation for the UNION virtual table. (check-in: 64af4ea91f user: drh tags: trunk)
2017-07-20
00:15
Update the size and performance graph. (check-in: d35ef36eeb user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to pages/changes.in.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
proc chng {date desc {options {}}} {
  global nChng aChng xrefChng
  set aChng($nChng) [list $date $desc $options]
  set xrefChng($date) $nChng
  incr nChng
}

chng {2017-07-20 (3.20.0)} {
<li> Update the text of error messages returned by [sqlite3_errmsg()] for some
     error codes.
<li> Add new interfaces [sqlite3_bind_pointer()], [sqlite3_result_pointer()], and
     [sqlite3_value_pointer()].
<li> Backwards-incompatible changes to some extensions in order to take 
     advantage of the improved security offered by the new [sqlite3_bind_pointer()]
     interface:
     <ul>
     <li> [Extending FTS5] &rarr; requires [sqlite3_bind_pointer()] to find
          the fts5_api pointer.
     <li> [carray(PTR,N)] &rarr; requires [sqlite3_bind_pointer()] to set the PTR parameter.
     <li> [https://www.sqlite.org/src/file/ext/misc/remember.c|remember(V,PTR)]
          &rarr; requires [sqlite3_bind_pointer()] to set the PTR parameter.
     </ul>
<li> Added the [SQLITE_STMT virtual table] extension.
<li> Added the [COMPLETION extension] - designed to suggest

     tab-completions for interactive user interfaces.  This is a work in progress.
     Expect further enhancements in future releases.
<li> Added the [sqlite3_prepare_v3()] and [sqlite3_prepare16_v3()] interfaces
     with the extra "prepFlags" parameters.
<li> Provide the [SQLITE_PREPARE_PERSISTENT] flag [sqlite3_prepare_v3()] and
     use it to limit [lookaside memory] misuse by [FTS3], [FTS5], and the
     [R-Tree extension].







|
















>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
proc chng {date desc {options {}}} {
  global nChng aChng xrefChng
  set aChng($nChng) [list $date $desc $options]
  set xrefChng($date) $nChng
  incr nChng
}

chng {2017-08-01 (3.20.0)} {
<li> Update the text of error messages returned by [sqlite3_errmsg()] for some
     error codes.
<li> Add new interfaces [sqlite3_bind_pointer()], [sqlite3_result_pointer()], and
     [sqlite3_value_pointer()].
<li> Backwards-incompatible changes to some extensions in order to take 
     advantage of the improved security offered by the new [sqlite3_bind_pointer()]
     interface:
     <ul>
     <li> [Extending FTS5] &rarr; requires [sqlite3_bind_pointer()] to find
          the fts5_api pointer.
     <li> [carray(PTR,N)] &rarr; requires [sqlite3_bind_pointer()] to set the PTR parameter.
     <li> [https://www.sqlite.org/src/file/ext/misc/remember.c|remember(V,PTR)]
          &rarr; requires [sqlite3_bind_pointer()] to set the PTR parameter.
     </ul>
<li> Added the [SQLITE_STMT virtual table] extension.
<li> Added the [COMPLETION extension] - designed to suggest
<li> Added the [UNION virtual table] extension.
     tab-completions for interactive user interfaces.  This is a work in progress.
     Expect further enhancements in future releases.
<li> Added the [sqlite3_prepare_v3()] and [sqlite3_prepare16_v3()] interfaces
     with the extra "prepFlags" parameters.
<li> Provide the [SQLITE_PREPARE_PERSISTENT] flag [sqlite3_prepare_v3()] and
     use it to limit [lookaside memory] misuse by [FTS3], [FTS5], and the
     [R-Tree extension].
Added pages/unionvtab.in.






































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<title>The UNION Virtual Table</title>
<tcl>hd_keywords unionvtab {UNION virtual table} {union-vtab}</tcl>
<fancy_format>
<!--<h1 align='center'>
The UNION Virtual Table
</h1>-->

<ol>
<li value=100><p>
The UNION virtual table (hereafter: "union-vtab")
is a [virtual table] that makes multiple independent
[rowid tables] tables look like a single large table.

<li value=110><p>
The tables that participate in a union-vtab can be in the same 
database file, or they can be in separate databases files that
are [ATTACH]-ed to the same database connection.

<li value=120><p>
The union-vtab is not built into SQLite.
Union-vtab is a [loadable extension].
The source code for union-vtab is contained in a single file located at
[https://sqlite.org/src/file/ext/misc/unionvtab.c|ext/misc/unionvtab.c]
in the SQLite source tree.

<li value=200><p>
A new union-vtab instance is created as follows:

<blockquote>
<b>CREATE VIRTUAL TABLE temp.</b><i>tabname</i> <b>USING unionvtab(</b><i>query</i><b>);</b>
</blockquote>

<li value=210><p>
Every union-vtab must be in the TEMP namespace.  Hence, the "<b>temp.</b>"
prior to <i>tabname</i> is required.  Only the union-vtab itself is required
to be in the TEMP namespace - the individual tables that are being unioned
can be any [ATTACH]-ed database.

<li value=220><p>
The <i>query</i> in the CREATE VIRTUAL TABLE statement for a union-vtab 
must be a well-formed SQL query that returns four columns and an 
arbitrary number of rows.  Each row in the result of the <i>query</i>
represents a single table that is to participate in the union.
<ol>
<li value=221'>
The first column is the schema name for the database that contains
the tables.  Examples:  "main", "zone512".
<li value=222'>
The second column is the name of the table.
<li value=223'>
The third column  is the minimum value for any rowid in the table.
<li value=224'>
The fourth column is the maximum value of any rowid in the table.
</ol>

<li value=230><p>
The <i>query</i> for the CREATE VIRTUAL TABLE statement of a union-vtab
can be either a [SELECT] statement or a [VALUES clause].

<li value=240><p>
The <i>query</i> is run once when the CREATE VIRTUAL TABLE statement is
first encountered and the results of that one run are used for all subsequent
access to the union-vtab.  If the results of <i>query</i> change, then
the union-vtab should be [DROP TABLE|DROP]-ed and recreated in order
to cause the <i>query</i> to be run again.

<li value=250><p>
There must be no overlap in the bands of rowids for the various tables
in a union-vtab.

<li value=260><p>
All tables that participate in a union-vtab must have identical
CREATE TABLE definitions, except that the names of the tables can be different.

<li value=270><p>
All tables that participate in a union-vtab must be [rowid tables].

<li value=280><p>
The column names and definitions for <i>tabname</i> will be the same as
the underlying tables.  An application can access <i>tabname</i> just like
it was one of the real underlying tables.

<li value=290><p>
No table in a union-vtab may contain entries that are outside of the
rowid bounds established by the <i>query</i> in the CREATE VIRTUAL TABLE
statement.

<li value=300><p>
The union-vtab shall optimize access to the underlying real tables
when the constraints on the query are among forms shown below.
Other kinds of constraints may be optimized in the future, but only
these constraints are optimized in the initial implementation.
<ul>
<li> <b>rowid=$id</b>
<li> <b>rowid IN</b> <i>query-or-list</i>
<li> <b>rowid BETWEEN $lwr AND $upr</b>
</ul>
<p>
Other kinds of constraints may be used and will work, but other
constraints will be checked individually for each row and will not
be optimized (at least not initially). 
All constraint checking is completely automatic regardless of whether
or not optimization occurs.  The optimization referred to in this bullet point
is a performance consideration only.  The same result is obtained
regardless of whether or not the query is optimized.

<li value=310><p>
The union-vtab is read-only.  Support for writing may be added at a later
time, but writing is not a part of the initial implementation.

<li value=320><p>
<i>Nota bene:</i>
The [sqlite3_blob_open()] interface does <u>not</u> work for a union-vtab.
BLOB content must be read from the union-vtab using ordinary SQL statements.
</ol>