News for hackers. Stuff that matters.
Re:Why I love databases by sklogic on Sunday November 09, 2014 @05:41PM (#8581163)
Most of the time a plain text file is good enough. Databases are overrated.
Re:Why I love databases by edraferi on Monday November 10, 2014 @11:00AM (#8584245)
JWZ wrote a great article about choosing between flat files and a database for Netscape Mail:

http://www.jwz.org/doc/mailsum.html

In Netscape 4.0, the new team went both C++ and Database happy, threw away the tightly-tuned mail summary files I had designed, and generally screwed the pooch raw.

My code had summary files that were on the order of 2% of the size of the folder they were summarizing, and was blazingly fast in all respects. The 4.0 code had an overhead closer to 30% (last time I checked) and was insanely slow, not to mention extremely fragile: their summary files got corrupted all the time.

Re:Why I love databases by ams6110 on Sunday November 09, 2014 @05:50PM (#8581187)
This is simply not true, otherwise we would all be using text files. Text files can work in some situations. I disagree that this is "most of the time."
Re:Why I love databases by sklogic on Sunday November 09, 2014 @06:34PM (#8581305)
We are using text files. How many programs in a typical Unix installation need to communicate to a database? Next to none. How many are communicating via text files? Almost all of them.
Re:Why I love databases by XorNot on Sunday November 09, 2014 @09:26PM (#8581757)
Try doing any remotely large data handling. I got midway through writing a direct disk CSV parser for some Python data analysis recently before I realized that this problem has been solved far better by SQLite.

A database is all about not reinventing the wheel for every problem. You shouldn't hand roll your own crypto, and if can avoid it you should also try not to hand roll those things other people make are already very good at.

Re:Why I love databases by sklogic on Monday November 10, 2014 @03:51AM (#8582570)
> Try doing any remotely large data handling.

I was doing grid computing stuff in experimental particle physics. Data as large as it gets. Flat tuple storage (initially on tapes) was all we needed, and we already have a much better way of handling tuples than anything that DBMSes could ever offer.

No databases whatsoever. Only streams, no random access.

Re:Why I love databases by SamReidHughes on Monday November 10, 2014 @12:57PM (#8585060)
What's an example of work you've done that used database systems that could have been better done using flat files?
Re:Why I love databases by sklogic on Monday November 10, 2014 @01:04PM (#8585098)
That's the point - I did not need any database systems whatsoever for nearly everything I ever done. Besides hierarchical DBMSes for CADs - but that's a totally different story, that's another area where RDBMSes fail miserably. There is no use for RDMBSes outside of the CRUD niche (which includes web, enterprise applications, and that's pretty much it).

I can't see any use for RDMBSes in the embedded world. No use for them in most of the data analysis tasks - stream storage works much better here. No RDBMSes in the system level (OSes, compilers, linkers, etc.). No RDBMSes in the scientific computing.

Re:Why I love databases by rpedela on Monday November 10, 2014 @05:36PM (#8587049)
I used to think the same thing as much of my early career was spent in graphics. Then I got much more familiar with relational databases and realized I was an idiot. For example I spent about 3 months hand tuning code that read a quad from a TB sized image stored on disk into a GPU so it could analyzed by computer vision algorithms. Then I realized that using a DB would have been about as fast and I would have saved 3 months of time. Unfortunately I didn't realize this until I left graduate school.

In conclusion, yes you often don't need a database and sometimes it is wrong tool but usually it saves you a lot of time because it is fast enough and general purpose enough.

Re:Why I love databases by sklogic on Monday November 10, 2014 @05:40PM (#8587084)
How exactly using an RDBMS would have helped accessing a plain two dimensional array?
Re:Why I love databases by rpedela on Monday November 10, 2014 @09:05PM (#8587873)
Accessing is easy. Making it fast enough off disk to feed the beast (GPU) is not. The DB has already solved that problem and given a really simple interface: SQL. My hand tuned code was probably faster but not enough to warrant 3 months of effort. I should mention this was several years ago and on a laptop since that was what the researchers used who needed to analyze the data. So I couldn't really solve performance issues with more RAM, etc.
Re:Why I love databases by sklogic on Tuesday November 11, 2014 @03:14AM (#8588836)
Sorry, I cannot believe this. SQL faster than mmap?!? Something unheard of. And I really do not understand why it should take 3 months to write a single line with an `mmap` call.
Re:Why I love databases by rpedela on Tuesday November 11, 2014 @08:22AM (#8589634)
There are a lot details I am leaving out because I don't have time or patience to explain them in a HN comment. That 3 months turned into an entire chapter (~15 pages) of my thesis. But I will tell you a little bit about it.

The data we were analyzing was biological and it wasn't actually an image. However it could reformatted as an image so we could apply computer vision algorithms to it. The thesis was first about the computer vision stuff being applied to biology and second about moving the computation to the GPU to speed it up. It went from ~1 hour to 15 secs when the computation was moved to the GPU. The problem with the GPU though is it only has so much RAM, and the PCIe bus to transfer data to it is rather slow. To make matters worse, getting data off disk is even slower and the GPU expects a certain data format for optimal processing.

The majority of the 3 months was not writing code. The majority of the 3 months was developing our own custom file format. The GPU wanted a particular format for optimal data transfer and the computer vision algorithms needed a particular format to be able to work. So it was about creating a file format that was fast off disk and through the PCIe bus and still had the correct formatting necessary for the computer vision algorithms. The exact specifics of the data format and why it had to be a certain way are what would take many pages of text to explain so I will stop.

If I used a DB instead, I could have simply put the data in a table and used rather simple SQL commands to get the data off the disk in the format the GPU and computer vision algorithms wanted. And it would have been about as fast and only taken maybe a week at most of effort (remember most of the time was spent on the data format). In other words, I could have graduated 3 months sooner which seems worth it to me.

Just to be clear, I never said SQL is faster than mmap although there are cases where it can be. What I said was it was usually not worth the effort to make it as fast or faster. It is kinda like C/C++ vs Python/Ruby/Javascript/etc. Yes your program will be a lot more efficient if you use C/C++, but is it really worth the time if you can do the same thing in a higher level language with little effort? There are cases where it is appropriate to use C/C++, but I would argue it is more the exception than the rule.

Databases are kinda like that for me now after learning how to use them properly. Can I beat them for my specific use case? Probably yes, but is it really worth the effort? Most of the time no, but there are exceptions.

Re:Why I love databases by sklogic on Tuesday November 11, 2014 @12:05PM (#8590864)
Very interesting indeed. Is your thesis published?

Btw., have you considered using a uniform memory architecture (e.g., Intel HD, or an embedded GPU)?

And I still cannot understand why do you need the "R" in "RDBMS" in your case. Sound like you could have been benefited from a simple tuple storage (see a bit of discussion in this thread). I doubt you need indexes and relations.

Re:Why I love databases by rpedela on Tuesday November 11, 2014 @12:49PM (#8591131)
It is published and you can find it somewhere in Purdue's library. It is not online though. It is a regret of mine that we didn't publish at a conference or journal, but at the time I was too concerned with getting out of there. I like school and research, but I didn't like the poverty.

At the time (2006), embedded GPUs were not available or just becoming available.

In this case, I didn't need relations but given the data size, indexes would have been very helpful since I had to retrieve quads so not to overflow GPU RAM. Any DB (in the most general sense) with indexing would have been fine. Since I can setup Postgres in about two minutes, that is easiest for me.

Re:Why I love databases by sklogic on Wednesday November 12, 2014 @04:25AM (#8594627)
So, back to my point - you did not need specifically RDBMS. I have nothing against tuple storages, stream DBMSes, berkeley-db style caches, etc. All my hate is reserved to the relational crap.
Re:Why I love databases by rpedela on Wednesday November 12, 2014 @09:13AM (#8595452)
Oh I see. Specifically for RDBMS and graphics: video game engines. Game engines are a bit weird because sometimes you need hierarchical data structures, stream processing, multi-core processing (e.g. physics), etc. I worked on a game engine for a few years, but again I did not know RDBMSes would be helpful. As far as I am aware, most game engines still do not use RDBMSes, but I think there are cases where they would make life a lot easier because parts of the game engine are relational.

For example, a game object often has many properties and those properties relate to other game objects or pieces of the game engine itself. A game object usually has a graphical representation, a physical representation, a representation related to animation, etc. And you need to keep these different representations in sync. If the physical representation moves, then the other representations have to be moved in sync with the physical one. If one of the representations gets deleted, then they all need to be deleted. So tables and foreign keys would make this a lot easier. It is necessary? No because you can do it with OO, inheritance, trees, but it is actually a lot of effort to do it that way.

That is one example, but I think there are several areas where RDBMSes can be helpful inside a game engine. Just to be clear, there are several areas in a game engine where RDBMSes make no sense too.

Re:Why I love databases by sklogic on Wednesday November 12, 2014 @11:31AM (#8596361)
Disclaimer: I don't know much about the graphics stuff.

Judging only by my experience in the other areas (which include CAD/CAE and GPGPU as the closest things to graphics), every time I needed to do something relational in nature, it was only dynamic data, never a relational storage. So I used quite a lot of Datalog. Never needed anything like SQL.

Re:Why I love databases by SamReidHughes on Tuesday November 11, 2014 @04:54AM (#8589106)
Yep, "using mmap" is worse performance-wise than what database engines do. It's not a suitable interface for shoveling data onto disk in a manner such that you can say, "I am done writing this to disk," and "This file will never be in an inconsistent state in the event of kill -9 or powerloss," with maximum performance. Also, it's not enough to cry "use mmap," if you don't want a corrupted file.

I think your antipathy towards relational databases has more to do with your unwillingness to learn how to use them than anything else. Otherwise you'd be capable of speaking with other people here on their level.

Re:Why I love databases by sklogic on Tuesday November 11, 2014 @11:58AM (#8590821)
I'm pretty well aware of how to use RDBMSes. I even implemented RDBMS engines before. In this case, nobody is writing into a file, so mmap should have been a perfect solution.
Re:Why I love databases by SamReidHughes on Monday November 10, 2014 @01:45PM (#8585390)
Why does iOS ship with SQLite then? I used it for an iPhone app that I wrote. It was more convenient than making my own flat file format.

> No RDBMSes in the system level (OSes, compilers, linkers, etc.).

OS X has them. Any OS with file search needs some kind of indexing technology.

As do mail clients, web browsers, and a bunch of other stuff that works with data.

It's a lot easier to add fast indexing after-the-fact when you didn't design up-front to use flat files.

Re:Why I love databases by sklogic on Monday November 10, 2014 @02:21PM (#8585619)
All the stuff you've mentioned is pretty niche, and, as someone mentioned somewhere above in this thread, mostly done this way by the cargo cultists who defiled the sacred Unix Way. Look at a typical Unix distribution, count how many packages depend on sqlite or berkeley db - a tiny proportion of a total number.

And, no, file search and all that fancy UI stuff has absolutely nothing to do with OSes. It's an application level.

Re:Why I love databases by bbcbasic on Sunday November 09, 2014 @09:01PM (#8581691)
Enterprise applications typically need a data store that offers multiple connections, transactions and atomicity.

Even for very simple apps though I like using a DB to store data, and then text files for import/export to other programs if necessary. Once you have a DB you get so much useful functionality without having to code.

Re:Why I love databases by sklogic on Monday November 10, 2014 @03:52AM (#8582573)
The fact that enterprisey coders got some weird habits does not mean they're doing it all the right way. Outside of the enterprise broken mindset there is very little use for the databases.
Re:Why I love databases by virmundi on Sunday November 09, 2014 @10:35PM (#8581908)
How many programs in a typical Unix installation are complex? Not many. Most of designed around the concept of pipes and filters. They don't need a database; they are transformative maps.

Complex systems often require complex data storage. If you have more than one process storing information into a file or set of files, you have to control that type of information. When faced with the option of writing complex, ACID like code or dropping in a PG or MySQL or SQLite option that takes from 1 MB to maybe 128 MB, most will go with using existing tools at the expense of RAM.

Is Oracle the solution for every project? Sure, if you're Oracle. However, one shouldn't throw out databases for alternatives simply because they are a bit complex. In fact, I think that raw file IO is more complex because it is not the norm.

Re:Why I love databases by sklogic on Monday November 10, 2014 @03:46AM (#8582558)
And how many programs need to be complex? Most systems are better off when built from a number of simple components, communicating via text protocols. If multiple entities want to store data in the same place, most likely you're doing something wrong.

I very rarely met things that really needed a database. And in most such cases it was not really a RDBMS. For example, a CAD needs a hierarchical database, relational does not fit there at all.

Re:Why I love databases by duaneb on Sunday November 09, 2014 @07:12PM (#8581386)
The file system is just a shitty db. Why does it matter whether it writes to a file system or to sqlite3?
Re:Why I love databases by sklogic on Sunday November 09, 2014 @08:04PM (#8581520)
Because all you need most of the time is a flat stream of characters. You don't need any of the DB crap, no random access, no indexes, no structure.
Re:Why I love databases by superuser2 on Sunday November 09, 2014 @08:52PM (#8581672)
It depends on the problem domain you are working in. I can't think of an application I've done where this wouldn't have required complex serialization and parsing. Those tools are already built for me in the form of ORMs and RDMSes. Why should I write my own?
Re:Why I love databases by sklogic on Monday November 10, 2014 @03:54AM (#8582584)
> It depends on the problem domain you are working in.

Unix is a pretty general purpose thing. And yet, you won't find anything in it that needs a database, nothing at all among hundreds of applications, including some fairly complex ones, like CAD/CAE tools, IDEs, compilers, etc.

> I can't think of an application I've done where this wouldn't have required complex serialization and parsing.

Are you doing CRUD mostly?

> Those tools are already built for me in the form of ORMs and RDMSes. Why should I write my own?

Parsing?!? In ORMs and DBMSes?!? C'mon, try to parse me some C++ with your Oracle.

Re:Why I love databases by duaneb on Monday November 10, 2014 @04:57PM (#8586794)
> Unix is a pretty general purpose thing.

Yea, until you want to query a normalized data set. Then unix is pretty miserable, because text is very ill-suited for indices and rapid and/or random access.

Re:Why I love databases by sklogic on Monday November 10, 2014 @05:37PM (#8587063)
Turns out, you need to do such things pretty rarely. Not "most of the time", as RDMBS proponents claim.
Re:Why I love databases by superuser2 on Monday November 10, 2014 @09:44PM (#8587997)
>Parsing?!? In ORMs and DBMSes?!?

What exactly do you think a database does? Provides a way to durably store tabular data on disk and read it back. Without a database, I have to make that myself by writing serialization routines to put my data structures on disk and parsing routines to go from "stream of characters" to my data structures.

DMBS places some limits on your data structures but does all that for you.

Re:Why I love databases by sklogic on Tuesday November 11, 2014 @04:24AM (#8589027)
If serialisation is hard for you, then you probably doing something badly wrong. In the tools I'm using it's done by a single line of code. And since most of the time data structures are trees or graphs, being sledgehammered into a tabular structure is not pleasant at all.
Re:Why I love databases by SamReidHughes on Monday November 10, 2014 @12:24PM (#8584828)
> Parsing?!? In ORMs and DBMSes?!?

Yes. Stuff stored in files has to be parsed when you read it out of files.

Re:Why I love databases by sklogic on Monday November 10, 2014 @12:38PM (#8584932)
And how exactly RDBMS crap could help with parsing? Mind parsing a C++ source file with your RDBMS?
Re:Why I love databases by SamReidHughes on Monday November 10, 2014 @12:41PM (#8584952)
The grandparent was talking about the serialization and parsing of the data that you'd be storing in flat files, not parsing of C++ files. Work that you avoid by using a DBMS.
Re:Why I love databases by sklogic on Monday November 10, 2014 @12:47PM (#8584989)
Parsing text files is not a problem at all. Never been a problem. And there are far too many benefits of having flat text streams vs. some inaccessible stupid binary ad hoc formats hidden inside some enterprisey RDBMS guts.
Re:Why I love databases by eropple on Sunday November 09, 2014 @08:53PM (#8581674)
Maybe you can replace a document database with the file system (though reinventing indexes for reasonable performance--which in so many use cases becomes remarkably important past a few hundreds of thousands of records--will be fun for you), but modeling relational concepts on the file system is both hard and time-consuming. And I'm comfortable saying that most nontrivial business applications are fundamentally relational.
Re:Why I love databases by sklogic on Monday November 10, 2014 @03:57AM (#8582591)
> And I'm comfortable saying that most nontrivial business applications are fundamentally relational.

Now try to assess, how many applications are supposed to be "nontrivial business applications". It's quite a niche thing, and that's where all this DBMS stuff belongs to. Please do not impose this crap on the rest of the world, we don't need your CRUD.

Re:Why I love databases by eropple on Monday November 10, 2014 @01:55PM (#8585460)
Why are you so randomly hostile about this? Your tone and attitude are super shitty throughout this thread. Chill.

As for CRUD--I'm a platform and devops engineer. I'm not a web developer (except incidentally). But I do often write relational things--like, say, "I have this node, running this application, using this artifact from that data store"--that are best modeled by a relational data store. They're otherwise trivial applications, but reinventing the relational data store would take orders of magnitude longer than writing the application against SQLite or Postgres. How do you propose to model relations across the file system in a way that doesn't make it the tail wagging the dog?

While I'm thinking about it, I'm pretty comfortable going further than "nontrivial business applications" to "a majority of networked applications". The world is relational. Modeling it relationally makes a lot of sense for a lot of use cases.

Re:Why I love databases by sklogic on Monday November 10, 2014 @02:30PM (#8585662)
No, it's RDBMS proponents who are hostile. Their attitude is "you will be assimilated, resistance is futile, we already won, so shut up and obey". This cannot and will not be tolerated.

I was pressured many times into giving up doing things the right way and adopting RDBMSes, and that was not pleasant at all. In some cases someone else who picked up that projects tried to move to RDBMSes (from hierarchical or document-oriented storages used before) and failed miserably.

So, again, I never came across anything that would need a relational storage. Not even when I was doing heavily distributed HPC (which is as "networked" as it gets). Yes, of course I did a lot of things that are relational naturally - but all of them were in Datalog, with no storage required.

Btw., wtf is "devops"? I've heard this a number of times recently, but nobody could explain the meaning.

Re:Why I love databases by eropple on Monday November 10, 2014 @03:33PM (#8586163)
Your anecdotes are interesting, but they don't present anything substantiative with regards to this discussion that merits this spittle-flecking you're trotting out here. Nobody's telling you to not do as you feel is right, at least not around here--what you describe isn't happening in this thread. You're being strangely aggressive and hostile just at the idea of using a relational data store to store relational data and I have no idea why.

As far as devops go, the lack of a solid term is why I use the term "platform engineering" for what I do. I build things to make other developers more productive and systems more responsive and scalable.

Re:Why I love databases by sklogic on Monday November 10, 2014 @05:35PM (#8587046)
Wait a minute. Cult of Codd is proclaiming that everything is relational and everyone should always use RDMBS, and if they don't, they're doing it wrong and wasting their time. OP went even further with claims that RDBMSes cover pretty much everything in the CS. If it's not an aggressive cult, I don't know what else could be more aggressive.

I'm ok with using RDBMS for storing relational data, everything has its niche and every tool could be used efficiently when needed. What I'm not ok with is when cultists try to force everyone else to use their precious hammer everywhere, for every little nail. I'm not ok when I'm told that if I did not use RDBMSes I did not do any large scale data analysis.

Re:Why I love databases by SamReidHughes on Sunday November 09, 2014 @09:57PM (#8581838)
How do you randomly access variable length fields in a text file and modify them and add new ones?
Re:Why I love databases by sklogic on Monday November 10, 2014 @12:38PM (#8584934)
Yes, web is a niche thing. Get over it.
Re:Why I love databases by sklogic on Monday November 10, 2014 @04:00AM (#8582603)
Why would I want to randomly access variable length fields in a file, to start with? It's a very niche thing to do. Filesystem driver may want to do something like this, some large scale caching proxy, probably. In most cases it's just an optimisation (like a berkeley db records backing text files such as /etc/passwd).
Re:Why I love databases by SamReidHughes on Monday November 10, 2014 @12:26PM (#8584839)
> Why would I want to randomly access variable length fields in a file, to start with? It's a very niche thing to do.

If by "niche" you mean every interactive website does it.