9 ms·
SQLite now allows multiple recursive SELECT statements in a single recursive CTE
- carterschonwald 6y agoDoes this mean it’ll be easy to do graph transitive closure computations in sqlite now?
- seg_lol 6y agoDo you mean iterating on an agency matrix dimension times to get the full path length between any two nodes? I have had to run my recursive queries external to the database (MySQL, SQLite), this change looks to bring it into the database. Excellent news!
- castratikron 6y agoTransitive closure will tell you if a path between two nodes exists, not the length of the shortest path between two nodes.
- whoisburbansky 6y agoYou're technically correct, but afaik there isn't really a way to compute transitive closure without also computing shortest paths along the way, modulo constant factors?
- simcop2387 6y agoYou'll compute paths along the way but won't know that they're the shortest path. Odds are good though that you'll havr found something good enough for most purposes though.
- whoisburbansky 6y agoIf all you do is iterate over the adjacency matrix, sure, but wouldn't Floyd-Warshall be the same time complexity? All I'm saying is that you get both pieces of information for essentially the same price, modulo constant factors.
- bawolff 6y agoEven if it is, i imagine its not going to be that efficient if it isnt optimized for that use csse.
- nikeee 6y agoI solved a task involving transitive closures in last year's Advent of Code using SQLite: https://github.com/nikeee/advent-of-code-2019/blob/master/06/main.sql https://github.com/nikeee/advent-of-code-2019/blob/master/06... How could this be improved with the new feature of SQLite?
- hehetrthrthrjn 6y agoIf I'm not mistaken, this brings SQLite up to parity with Datalog.
- lactobacillis 6y agoCan you please expand on this. Thanks
- slifin 6y agoUnless you're using Clojure engines with Datomic pull syntax, SQL engines (most? all?) can't pull out nested results without serialization nastiness
- simonw 6y agoThis means you can use SQLite as a graph database. The draft documentation for this feature talks about that in more detail here: https://sqlite.org/draft/lang_with.html#rcex3 https://sqlite.org/draft/lang_with.html#rcex3 Also relevant: the draft changelog for the next version (due out in December): https://sqlite.org/draft/changes.html https://sqlite.org/draft/changes.html
- roenxi 6y agoI don't know anything about graph databases, but ... why do we want to use SQLite as one? Doesn't the graph database community have something better to offer? SQL has a knack for doing really easy things well, and moderately complicated things badly. I would assume by default that anything involving graphs should not involve SQL. Recursive CTEs to me scream "you're about to spend hours debugging something trivial".
- zimpenfish 6y ago> Doesn't the graph database community have something better to offer? Probably not in the same kind of resource-constrained way, no. Whilst it might be a suboptimal graph database, it's also not going to require 2GB of RAM to run...
- oever 6y agoAn interesting upcoming graph database is oxigraph. It's written in Rust and might be able to cope well in 2GB. https://github.com/oxigraph/oxigraph/ https://github.com/oxigraph/oxigraph/
- zimpenfish 6y agoOoh, ta, that looks handy, especially with supporting SPARQL. If it can load my 1.1GB TTL, I'll be beyond happy.
- pbronez 6y ago
- molyss 6y agoThe thread is here : https://fossil-scm.org/forum/forumpost/bacf8cf88c?t=h&unf https://fossil-scm.org/forum/forumpost/bacf8cf88c?t=h&unf
- anitil 6y agoI loved everything about that thread. Slightly off-topic, but I want to point out how well Richard deals with a slightly rude commenter [1]. Keeps it classy and productive while still calling out the bad behavior. [1] https://fossil-scm.org/forum/forumpost/7817eb709d?t=h https://fossil-scm.org/forum/forumpost/7817eb709d?t=h
- twic 6y agoThe commenter's comment [1] is absolutely fine, though. Hipp's response is also fine! The only thing that wouldn't be fine is if someone inappropriately reacted to that comment as an insult. [1] https://fossil-scm.org/forum/forumpost/7840137009?t=h https://fossil-scm.org/forum/forumpost/7840137009?t=h
- anitil 6y agoIt's possible I'm misreading the tone of "has ways to go" and "niche volunteer-based SCM".
- 0xffff2 6y agoIf anyone comes across as rude in that exchange it's Richard. Maybe it's just his style (I don't have any experience to judge by except this comment), but he comes off as very abrupt here.
- ChuckMcM 6y agoVery nice. Graph following for the win. I wrote an inventory control system about 10 years ago that achieved this in a very hacky (read code outside SQLite) way. The requirement was to be able to track items, track users of items, track how much time an individual user had used and item, and to track maintenance and repairs of items. The would let you "charge back" wear and tear on things to the most responsible party, and to provide lifetime information in order to buy replacements in a timely way. All that hackyness would be a single statement with this change.
- chillfox 6y agoNice, I was about to pull RedisGraph in to a small project using SQLite to do two graph queries.
- lijogdfljk 6y agoAnyone have a recommended resource for understanding the practical application of recursive CTEs / Graph DBs?
- chmod775 6y agoGoing out on a limb here because your question can be interpreted in multiple ways and I only feel qualified to answer one of them: The most common example for graphs in DBs would be a graph representing the friends/contacts of users. It's one of these "you'll know when you need it" solutions. Sometimes your data structure is a graph, and sometimes you want that graph to live in a database. And in even rarer cases you want to search that graph in your database in some recursive manner.
- jslakro 6y agoWhat about representing states? Not sure about how graph dbs could perform on that scenario. There is a recent post talking about the topic and I'm still thinking about the best solution to store flows or similar. https://news.ycombinator.com/item?id=24764303 https://news.ycombinator.com/item?id=24764303
- malkia 6y agoI've used them (in postgresql) to evaluate the merging of "parent" and "child" values - e.g. one row can be parent, and if the child has NULL for value it takes it from the parent (though do not remember much of the details). This can go to deeper just first parent, but parent of parent too. I was able to make a query like this in PostgreSQL, but forgot the details of how I did it (though once you sit down, you get it eventually).
- dliff 6y agoIn the past I used recursive CTEs in Postgres to calculate the BOM of a product. Products consisted of "parts", and each "part" had a cost and could consist of any number of other "parts" (subassemblies). This was for a homemade ERP resembling software.
- 6y ago
- deleted 6y ago[deleted]
- frou_dh 6y agoI don't like SQLite because of this: https://www.sqlite.org/datatype3.html https://www.sqlite.org/datatype3.html > The type affinity of a column is the recommended type for data stored in that column. The important idea here is that the type is recommended, not required. Any column can still store any type of data. I simply don't want weird rows (that violate the _expressly declared_ type of a SQL table) to be merrily allowed into persistent storage.
- sradman 6y ago> Why on earth would I want weird rows (that violate the _expressly declared_ type of a table) to be merrily allowed into persistent storage? Some problems are easy to solve given a column of type VARIANT: 1. simple sparse columns instead of a multi-type EAV table, 2. a BIG Table style schema that is easily range partitioned. The main reason in SQLite is that most SQL dialects just work. SQLite becomes a universal desktop workbench for SQL. This flexibility also applies to things like delimited identifiers [1]. The problem is not that SQLite uses VARIANT datatypes, the problem is that once a datatype is specified it is not enforced by the engine. SQLite could/should add a PRAGMA to enable Domain Integrity much like it does with Foreign Keys (PRAGMA foreign_keys = ON;). [1] https://sqlite.org/lang_keywords.html https://sqlite.org/lang_keywords.html
- frou_dh 6y agoI remember hearing something along the lines of the odd typing in SQLite being vestigial from its early days when it was closely aligned with Tcl.
- sradman 6y agoI'm not sure of the original inspiration but SQLite's core storage types with variable length encoding but it is the right way to implement a row store or a data serialization format, in my opinion. Fixed length data types in SQL were a premature optimization that led to verbose syntax like LONG VARCHAR FOR BIT DATA [1] and incompatibilities tied to internal implementation details. There is no reason why more specific constraints can't be specified on top of the core storage types. One can argue that SQLite is sorely missing an exact NUMERIC type but that holds true for most/all language runtimes as well. Datetime is a bit weird too but the format of the DB file is a thing of beauty. [1] https://db.apache.org/derby/docs/10.1/ref/rrefsqlj30118.html https://db.apache.org/derby/docs/10.1/ref/rrefsqlj30118.html