You Shouldn't Use SQLite
[2021]<p>I have a few concerns about this article.  First, a summarization.<p>This is the event which raised the author&#x27;s concern:<p>&gt; Caifan Du asked what the best way would be to store about 16GB of research data efficiently since it was becoming extremely slow to work with on her own computer. Almost immediately the idea was brought up to simply drop everything into an SQLite database.<p>The author raises two points.  First, the author notes that SQLite&#x27;s purported max DB size (281 TB) is not worth talking about because there is no single hard disk big enough to hold 281 TB.  Next, the relates an experience: They downloaded ~600,000 text files of the Congressional Record (<a href="https:&#x2F;&#x2F;www.congress.gov&#x2F;congressional-record" rel="nofollow">https:&#x2F;&#x2F;www.congress.gov&#x2F;congressional-record</a>), for the period from 1994 up to &amp; including May 2021, into a single folder of his (presumably macOS) system.  Opening the folder caused the Finder to hang.  He then stored all of the files into a single SQLite database.<p>His code, which he previously had accessing files in the directory, is now taking many times longer to run when it accesses &#x27;files&#x27; through the SQLite database.  It turned out that the SQLite database was being queried by filename (which was one of the columns), but that column was not indexed.  Since there was no index, SQLite was doing a full table scan on every &#x27;open file&#x27; query.<p>I would like to respond to both points, since this is at least partially in my wheelhouse (thanks to my day job).<p>Mr. Erz, you are correct that there is no single drive that can hold 281 TB.  But, even with macOS, it would be possible to directly connect enough storage to hold 281 TB.  For example, starting with a Mac with Thunderbolt 3, you could…<p>• Connect via Thunderbolt to a ATTO ThunderLink SH 3128 SAS adapter<p>• Connect via two SAS cables to a Colfax CX42412s-JBOD 24-drive JBOD, containing 24 HGST 0F38357 16-TB SAS drives.<p>You can then use macOS RAID Assistant to format the drives RAID 0, giving you ~384 TB raw capacity, or ~349 TiB raw capacity, which should be enough to hold 281 TB.<p>I should say, it would be very unlikely that someone would do this.  Instead, that JBOD would probably be connected to a server, which would then server those ~349 TiB (raw) to your computer over a network protocol like SMB.  There are also network filesystems like Lustre, which use clusters of servers, each with its own direct-attached storage.  In such an environment, software running on the clients takes commands like `list directory`, connects to and queries the relevant servers, and returns the results.  My colleague Stéphane runs a service (Oak, <a href="https:&#x2F;&#x2F;uit.stanford.edu&#x2F;service&#x2F;oak-storage" rel="nofollow">https:&#x2F;&#x2F;uit.stanford.edu&#x2F;service&#x2F;oak-storage</a>) which uses Lustre, and has a capacity of many Petabytes.<p>There may be other reasons why having a single 281 TB SQLite database is a bad idea, but that is out of scope in this case.<p>Next, a side comment on storing 600,000 files in a single directory.  On the systems I run at work, such a directory would also take a long time to list.  That is common for most environments where the `list contents of directory` operation is synchronous; the client (you) will have to wait for the OS to gather the information and organize it.  Languages like Python also see this issue; it is the reason why `os.scandir` is often better to use than `os.listdir` (see <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;59749854&#x2F;how-does-os-listdir-performs-on-very-large-folders" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;59749854&#x2F;how-does-os-lis...</a>).<p>Finally, storing &#x27;files&#x27; into a SQLite database.  SQLite actually ships a tool for making &quot;SQLite archive&quot; files, which are what you describe: A SQLite database with a single table, containing each file&#x27;s contents in a column.  The `sqlar` schema is described in <a href="https:&#x2F;&#x2F;www.sqlite.org&#x2F;sqlar.html" rel="nofollow">https:&#x2F;&#x2F;www.sqlite.org&#x2F;sqlar.html</a>, and it addresses the concern you raised in your article: The `sqlar` schema has the filename as a primary key.  Doing so does not eliminate the integer row ID, but it does automatically create an index on the filename; it also ensures that filenames are unique.<p>`sqlar` also has another benefit, something you wanted : The file contents are stored in compressed format.  The database itself is not compressed, but the file is.<p>In summary, you are correct that no single hard drive would store so much data, but even on macOS it is (theoretically) possible to have that much data directly connected, and it is practically possible with a SMB connection to a storage server, not to mention network file system platforms like Lustre.  As for SQLite, the problem of not indexing is a vexing one, and a problem that database developers will always encounter (cf <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=31170370;" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=31170370;</a> for this context, sharding may be thought of as another form of indexing).  But please do not &quot;throw the baby out with the bath water&quot;.  The SQLite team themselves document and implement a schema you could have used.  I ask you to reëvaluate your dislike of SQLite, and if you have some time, maybe try again, using the `sqlar` schema this time :-)<p>~ Karl<p>N.B.  You may also be thrilled to learn that pandas now supports reading a SQL query into a DataFrame: <a href="https:&#x2F;&#x2F;pandas.pydata.org&#x2F;pandas-docs&#x2F;version&#x2F;0.15.0&#x2F;generated&#x2F;pandas.read_sql.html" rel="nofollow">https:&#x2F;&#x2F;pandas.pydata.org&#x2F;pandas-docs&#x2F;version&#x2F;0.15.0&#x2F;generat...</a>