6 ms·
The biggest news, of course, is the addition of the long-awaited STRICT mode which fixes SQLite's biggest shortcoming (at least from a particular perspective) b
by ComputerGuru 5y ago
The biggest news, of course, is the addition of the long-awaited STRICT mode which fixes SQLite's biggest shortcoming (at least from a particular perspective) by turning into a proper, strongly-typed datastore.
https://www.sqlite.org/stricttables.html https://www.sqlite.org/stricttables.html
- Lio 5y agoThere’s nothing obvious is linked release but is this expected to have an affect on performance either good or bad?
- SQLite 5y agoThe SQLite dev's internal performance testing using cachegrind shows that STRICT mode uses about 0.34% more CPU cycles. So STRICT is slightly slower, but not enough that you could measure the difference reliably in a real-world system.
- ripley12 5y agoI wouldn't expect much difference in performance. "The on-disk format for the table data is the same." I would expect the additional checks on writes to be negligible in most cases (dwarfed by other bookkeeping and I/O). I imagine that strict mode could enable some optimizations for read queries, but I can't see those being huge wins.
- ComputerGuru 5y ago> but I can't see those being huge wins. I agree from an algorithmic perspective but in the real world, it really depends. The size of a non-text/binary cell within a column is now fixed, meaning guaranteed to never need to resize/reallocate when streaming results. That could translate to non-negligible improvements (multiple percentage point speed up) if it’s implemented separately from the existing code path.
- prirun 5y ago> The size of a non-text/binary cell within a column is now fixed I think this is not true since the on-disk format didn't change, ie, ints are still variable-size whether strict or not.
- ComputerGuru 5y agoThe format/spec doesn’t change, the implementation does. “This field can be variably sized” vs “but in practice since this is a strict table it will always be exactly n bytes”
- ComputerGuru 5y agoIt’s really no more than an additional (hyper optimized) check constraint on the type; with branch prediction it’s probably ~free.
- michalc 5y agoI have been particularly looking forward to that. Although I have to admit that I'm a bit... disappointed(?)... that previous versions of SQLite won't be able to open such tables (unless they use PRAGMA writable_schema=ON). I wonder if SQLite didn't store the schema for a table as a "CREATE TABLE..." string, but instead something a bit more... structured, then such things could be added in a more backwards compatible way?
- deleted 5y ago[deleted]
- cryptonector 5y agoThis could never be added in a backwards-compatible way if the existing CHECK() functionality was not sufficient already. And yes, it'd be very nice to have a relational metaschema that doesn't suck for SQL schema. So far all such metaschemas I've seen leave a lot to be desired.
- porker 5y agoWhat kind of thing do you mean by a relational metaschema?
- formerly_proven 5y agoDescribing SQL tables with an SQL table
- jhgb 5y agoThat's called a catalog. (https://reldb.org/c/index.php/twelve-rules/ https://reldb.org/c/index.php/twelve-rules/, Rule #4)
- ComputerGuru 5y agoThe existing check syntax would cover inserts but wouldn’t have supported the behavior of the new “any” type in a strict table. What would be nice is if SQLite had separate “compatible with” and “read-only compatible with” fields, since the read-only behavior should not have changed at all (although I suppose describing the table would fail depending on how the presence of the STRICT modifier is codified).
- dkjaudyeqooe 5y agoGiven that it has the Any type, it's really not that much different, it's mostly the lack of the 'interesting' best-effort automatic conversions which confused and alarmed people and gave SQLite's type system a bad name. This version still does automatic conversions, which IMO are always a bad idea, but justifies them with "but everyone is doing it!". Some people seem to object to the Any type, but it's incredibly useful since a column may naturally contain a different type per row and it avoids ugly hacks to accommodate them.
- contingencies 5y agoCouldn't resist. https://imgur.com/a/W3nufMT https://imgur.com/a/W3nufMT
- belter 5y agohttps://youtu.be/st6-DgWeuos https://youtu.be/st6-DgWeuos
- brandmeyer 5y agoHot take: The ANY column type will never be used. Users who want to take advantage of it will just avoid the STRICT keyword on the whole table (maybe even the entire database). Users who like STRICT typing will reach for a JSON column for their occasional weakly- or sum-typed needs.
- brigandish 5y agoANY acts differently between strict and non-strict[1]: > The behavior of ANY is slightly different in a STRICT table versus an ordinary non-strict table. In a STRICT table, a column of type ANY always preserves the data exactly as it is received. For an ordinary non-strict table, a column of type ANY will attempt to convert strings that look like numbers into a numeric value, and if successful will store the numeric value rather than the original string. So it has some utility in a strict table that you can't get otherwise. [1] https://www.sqlite.org/stricttables.html#the_any_datatype https://www.sqlite.org/stricttables.html#the_any_datatype
- CyberDildonics 5y agoWhat's the difference between a datastore and a database?
- ffwd 5y agoCREATE TABLE if not exists boxoffice (title ANY, theaters ANY, release_date ANY, year ANY) STRICT;
- SPBS 5y agoSTRICT tables forbid the use of any other types besides INT/INTEGER, REAL, TEXT, BLOB (and ANY). What about TIMESTAMP? DATETIME? You can't use that as a type name anymore. Either pick INT, REAL or TEXT for that. What about JSON? You can't use it as a type name anymore. Pick TEXT. Basically type names, even if SQLite didn't have explicit support for that type, were helpful documentation hints in what the column contained. Now everything devolves to either INT or TEXT. I have UUID fields, I can't even call them UUID or BINARY(16), just BLOB.
- melony 5y agoAnd more importantly, JSON.
- derefr 5y agoNote that you don't have to have a JSON-typed column in SQLite in order to do JSON-y things. In SQLite, JSON is just "text that happens to contain JSON", and JSON functions are just functions that operate on "text that happens to contain JSON".
- derefr 5y agoPresumably the point of the strict typing forbidding aliases here, is to force the developer to realize/acknowledge that SQLite does not in fact have separate internal native types with these names. It's like the modern C convention of avoiding "int" in favor of u8/u16/u32/u64. Rather than pretending "int" is a separate thing, you have to explicitly choose and acknowledge the concrete primitive type you're really getting, and explicitly opt into the semantics that use of that concrete primitive type implies.
- nayuki 5y agoNot a great analogy because the semantics of the classic C types still leak through. For example, ((uint16_t)0xFFFF) * ((uint16_t)0xFFFF) would cause undefined behavior if int is 32 bits wide, due to implicit arithmetic promotions. Also, many APIs of the C standard library are defined to take or give char/int/etc., and it takes effort to translate between those types and u8/u32/etc. in a safe way that works on all platforms.
- chmaynard 5y agoAs I understand it, STRICT is not a database "mode" but rather a feature of individual tables. In other words, strict and non-strict tables can co-exist in the same database.