No ROWID optimization (The WITHOUT ROWID Optimization)

Excerpt: https://www.sqlite.org/withoutrowid.html#wtu

 
1.0 Introduction
By default, each row in SQLite databases have a special column called the rowid uniquely identifies a row in the database table that column. However, if you add WITHOUT ROWID keyword after the CREATE TABLE statement, this will disable the rowid column. Sometimes Omitting rowid, it can bring to enhance the space and performance.
1.1 Syntax
now create an WITHOUT ROWID table, the most direct way is to add keywords WITHOUT ROWID after the CREATE TABLE statement such as:.
CREATE TABLE IF wordcount the NOT EXISTS (
  Word TEXT PRIMARY KEY,
  cnt INTEGER
) WITHOUT ROWID;
as all the other Like SQL syntax, keywords are not case sensitive. Any of the following methods are acceptable:
the WITHOUT the ROWID, withoutrowid, the WITHOUT the ROWID they represent a meaning.
 
Note: If the table is specified WITHOUT ROWID attribute table must specify PRIMARY KEY. Otherwise, when you create a table, returns an error, the error generally means that the designated WITHOUT ROWID create table statement lacks PRIMARY KEY.
 
In most cases, rowid and oid or _rowid_ on behalf of a meaning. However, only rowid can appear in the table creation statement among.
 
1.2 compatibility
only after the SQLite 3.8.2 version of the program can only be used WITHOUT ROWID keyword. Earlier versions of SQLite open carry WITHOUT ROWID attribute table will return an error of a malformed database schema.
 
1.3 Quirks (particularity)
To date, WITHOUT ROWID can only be used SQLite database, the other database engines are not compatible with the keyword. In the orthodox system, even without WITHOUT ROWID keyword, all tables should performance and effectiveness WITHOUT ROWID same. However, SQLite in the beginning was designed on the use of ROWID integer to simplify the way of implementation. This method performs well for many years. But with the growth in demand for SQLite, (the need for tables in which the PRIMARY KEY really did correspondto the underlying row key grew more acute) for table specifies PRIMARY KEY attributes become more urgent, and therefore rowkey contradictions more acute. For compatibility with the past it has been used for a long time in the program, and therefore without concept rowid was finally added to SQLite in, (The WITHOUT ROWID concept was added in order to meet that needwithout breaking backwards compatibility with the billions of SQLite databasesalready in use at the time (circa 2013).)
in order to seamlessly compatible with thousands of past programs, WITHOUT ROWID concept is added to the SQLite.
2.0 and carry different tables at the Rowid
WITHOUT ROWID is an optimization option. She did not provide any new features (capablilities). ROWID operating table and operating table carry do not carry ROWID, they are using the same syntax. The only advantage is to save disk space and is faster than ordinary table.
 
In most cases, do not carry and carry table rowid rowid table are interchangeable (Interchangeable). However, there are some limitations WITHOUT ROWID table, but these limitations are common rowid table does not have.
 
1. Specify the table WITHOUT ROWID must specify PRIMARYKEY, or fail to build the table
2 specifies WITHOUT ROWID table can not specify INTEGERPRIMARY KEY. In an ordinary table, "INTEGER PRIMARY KEY" means that thecolumn is an alias for the rowid. But since there is no rowid in a WITHOUTROWID table, that special meaning no longer applies. An "INTEGER PRIMARYKEY" column in a WITHOUT ROWID table works aN like "INT PRIMARY kEY" Ordinary aN column in the table:. It iS a PRIMARY kEY that has integeraffinity
3 specifies WITHOUT ROWID table can not use AUTOINCREMENT keyword

Guess you like

Origin blog.51cto.com/fengyuzaitu/2429647