Live data from Hacker News

Show HN: Simple-graph – a graph database in SQLite

github.com

21–30 of 44 posts

Re: Show HN: Simple-graph – a graph database in SQLite

#21
Interesting. SQLite is awesome.

I did something similar recently, a block store for a rust implementation of ipfs, which models a directed acyclic graph of content-addressed nodes.

https://github.com/actyx/ipfs-sqlite-block-store

I found that performance is pretty decent if you do almost everything inside SQLite using WITH RECURSIVE.

The documentation has some really great examples for WITH RECURSIVE. https://sqlite.org/lang_with.html

Re: Show HN: Simple-graph – a graph database in SQLite

#22
post #16
post #9

Earlier quoted context omitted.

Neo4j has failed queries I have written, with "out of memory" errors. I have never, ever, ever gotten that from SQLite.

Performance issues are a very valid discussion. But to me, the availability of a graph-oriented query language on top of this graph variant of SQLite is, imho, the very first step to investigate. (RDF import/CSV import being next)

There has been a lot of progress on creating standardized query languages for graphs. The two most notable ones are [2]:

- SQL/PGQ, a property graph query extension to SQL is planned to be released next year as part of SQL:2021.

- GQL, a standalone graph query language will follow later.

While it is a lot of work to design these languages, both graph database vendors (e.g. Neo4j, TigerGraph) and traditional RDBMS companies (e.g. Oracle [2], PostgreSQL/2ndQuadrant [3]) seem serious about them. And with a well-defined query language, it should be possible to build a SQL/PGQ engine in (or on top of) SQLite as well.

[1] https://www.linkedin.com/pulse/sql-now-gql-alastair-green/

[2] http://wiki.ldbcouncil.org/pages/viewpage.action?pageId=1062...

[3] https://www.linkedin.com/pulse/postgresql-oracle-graph-query...

Re: Show HN: Simple-graph – a graph database in SQLite

#23
post #10

Tangentially related to graph dbs, but if you're looking for more hierarchical support, SQLite does has a transitive closure extension[0] that might be of some assistance. I leveraged this back in 2014 to write our framework-agnostic result storage on AWS Device Farm. [0] - https://www.sqlite.org/cgi/src/artifact/636024302cde41b2bf0c... [1] - https://charlesleifer.com/blog/querying-tree-structures-in-s...

I've actually been working on an extension to perform breadth first search queries in SQLite on general graphs [0]. The extension is actually based off of the transitive closure extension. You can use it on any existing SQLite database as long as you can wrangle your edges into a single table (real or virtual) and the node ids are integers (I'm planning on removing this constraint in the future).

[0]: https://github.com/abetlen/sqlite3-bfsvtab-ext

Re: Show HN: Simple-graph – a graph database in SQLite

#25
post #21

Interesting. SQLite is awesome. I did something similar recently, a block store for a rust implementation of ipfs, which models a directed acyclic graph of content-addressed nodes. https://github.com/actyx/ipfs-sqlite-block-store I found that performance is pretty decent if you do almost everything inside SQLite using WITH RECURSIVE. The documentation has some really great examples for WITH RECURSIVE. https://sqlite.…

The issue I found with WITH RECURSIVE queries is that they're incredibly inefficient for anything but trees. I've looked around and there doesn't seem to be any way to store a global list of visited nodes. This means that when performing a traversal of the graph the recursive query will follow all paths between two nodes.

Re: Show HN: Simple-graph – a graph database in SQLite

#26

How does this perform compared to a “native” graph database like Neo4J?

It really depends on what you want to do with it. I would benchmark the tasks "traversal", "aggregation" and "shortest past" for a 10k to 10M node graph. Anything under 10k would be good enough with most techs and over 10M need to consider more tasks (writes, backup, the precise fields queried can become their particular problems at larger scale). The Github link implements "traversal "in Python instead of pure SQLit…

> Traditional relational OLTP databases such as Postgres are already faster than dedicated graph databases for certain graph related tasks

It is indeed quite common that relational databases outperform graph databases on certain graph processing problems such as subgraph queries (a.k.a. graph pattern matching). There are two key reasons for this: (1) most graph pattern matching operations can be formulated using relational operations such as natural joins, antijoins, and outer joins; and (2) relational databases have been around longer and have well-optimized operators.

A lot of the value that graph databases provide lies in their query languages which (for most systems) allow formulating path queries using a nice syntax (unlike SQL's WITH RECURSIVE which many people find difficult to read and write). Their property graph data model supports a schema-optional approach, which makes them better suited for storing semi-structured data. They also "provide efficient programmatic access to the graph, allowing one to write arbitrary algorithms against them if needed" [1].

With all these said, graph databases could be much faster on subgraph queries than relational databases and there are recent research results on the topic (worst-case optimal joins, A+ indexes, etc.). But these are not available in any production system yet.

[1] http://wp.sigmod.org/?p=1497

Re: Show HN: Simple-graph – a graph database in SQLite

#27

How does this perform compared to a “native” graph database like Neo4J?

It depends on how the graph is stored in the database. In this project the nodes ids are TEXT so it will likely not scale very well. I know because I use a similar implementation with GUID as string in Sqlite in a project since a couple of years and while it works fine for the graph I have (<1 million nodes, few edges per nodes) it won’t perform too well past that.

To some extent I think it depends on what data you're storing in the graph ie. If it's temporal data using a ulid instead of a guid speeds things up significantly (30x for large data) as your ids are not as fragmented.

https://github.com/schinckel/ulid-postgres/blob/master/ulid....

Re: Show HN: Simple-graph – a graph database in SQLite

#29
post #16

Earlier quoted context omitted.

Performance issues are a very valid discussion. But to me, the availability of a graph-oriented query language on top of this graph variant of SQLite is, imho, the very first step to investigate. (RDF import/CSV import being next)

There has been a lot of progress on creating standardized query languages for graphs. The two most notable ones are [2]: - SQL/PGQ, a property graph query extension to SQL is planned to be released next year as part of SQL:2021. - GQL, a standalone graph query language will follow later. While it is a lot of work to design these languages, both graph database vendors (e.g. Neo4j, TigerGraph) and traditional RDBMS com…

have SPARQL and Gremlin not seen adoption as standard graph traversal languages? They're the two names that spring to mind when I think "graph querying".

Re: Show HN: Simple-graph – a graph database in SQLite

#30
I really like this, OP. I'm member of the clan "why are you creating your own XDR, just use sqlite!!" and have oft jumped to that in technical discussions, so appreciate it.

However, what's lacking from something like this is a detailed bill of the cost. I'd love to see some, any benchmark on a DB with > 10^6 edges to see how it goes. That's the other hand of the equation "just use sqlite and be happy" -- the expectation that performance will actually be reasonable.

Post reply on HN