News for hackers. Stuff that matters.
Re:Why you should never use MongoDB (2013) by lmm on Monday August 15, 2016 @12:24PM (#12291459)
> Like the author, I really cannot wrap my head around this. While I understand that duplicating documents across collections may make querying faster, what about when you want to change the document? You need to propagate the change across every duplicate of the document in every collection where it exists. This means that any "de-duplication" logic needs to happen at the application level, rather than the database level.

You're assuming that you need to change things. Almost all big-data approaches work better when you abandon that and go for a log-structured model where you only ever append.

> I think the real issue is that "if you have a hammer, everything looks like a nail." Mongo and other NoSQL stores have some real use cases, but people who are more familiar with Mongo than RDBMS are too trigger happy to employ it as a solution to problems where a RDBMS is the clear solution.

True enough, but I think the converse is more true. If you're using a traditional RDBMS you're accepting a big series of constraints in exchange for functionality you often don't use. Indices are updated synchronously on every insert, slowing your writes, for the sake of transactional guarantees that most applications aren't written to take advantage of. Queries have to be passed over the wire as strings, so your application will spend a significant chunk of its time building them (hopefully using a library without vulnerabilities to send them over the wire so the database can spend a significant chunk of its time parsing them), or else you get to deal with the db-specific and per-connection quirks of prepared statements, for the sake of supporting ad-hoc querying in a language that frankly isn't great for humans. Tables, materialized views and the like occupy this awkward in-between condition where it's not clear whether you're supposed to create and modify them ad-hoc (and manipulate them programatically) or not; if you really do need to do ad-hoc reporting then they're what you want, but often the performance implications of that make it unacceptable to do in production.

I don't think a lot of cases are good fits for RDBMS. If you don't need ad-hoc reporting then you're better off building a data processing pipeline where you produce your results directly rather than the sort of semi-aggregating you end up with with an RDBMS. If you don't need full ACID then it's not worth paying the performance cost of it. And I don't know why there aren't RDBMSes without better query languages and schema definition languages, but there aren't.

Re:Why you should never use MongoDB (2013) by breischl on Monday August 15, 2016 @03:02PM (#12292633)
>>Queries have to be passed over the wire as strings, so your application will spend a significant chunk of its time building them... or else you get to deal with the db-specific and per-connection quirks of prepared statements...

Or you could use stored procedures. Think of it as making your RDBMS into a microservice, if you like.

>>I don't know why there aren't RDBMSes without better query languages and schema definition languages Huh... I always thought SQL was pretty straightforward for most cases. It only gets really arcane when you get into advanced cases (eg, recursive queries) and/or vendor extensions. It does take a bit of a mental shift, but no more so than imperative-style to functional-style, IMO.

There are certainly tradeoffs to using an RDBMS. But I think a lot of people jump to the conclusion that they have a big-data situation when they really don't. I also think a lot of people underestimate the value of very easy ad-hoc querying and already-solved backup/restore.

Re:Why you should never use MongoDB (2013) by lmm on Monday August 15, 2016 @03:36PM (#12292834)
> Or you could use stored procedures. Think of it as making your RDBMS into a microservice, if you like.

The trouble is testability, versioning, deployment, and SQL just not being a pleasant language for expressing business logic. And the lack of a library ecosystem. And poor IDE support. And...

Re:Why you should never use MongoDB (2013) by breischl on Monday August 15, 2016 @03:58PM (#12292956)
>>SQL just not being a pleasant language for expressing business logic

No kidding - don't do that. Sprocs are great to present a query interface and avoid sending queries over the wire every time. They can be handy to decouple the actual storage architecture from the query interface, so you can do tricky stuff in SQL without screwing up the clients. That doesn't mean you should stick your business logic in there.

>>testability, versioning, deployment... library ecosystem...

And how would any of those problems be solved by using raw SQL strings or a document DB? That just moves the problems back into the schema or the data, where it's even harder to deal with.

>>poor IDE support

So your code editor has a better IDE for SQL? Or are we talking about a document DB? I haven't seen any of them that were anywhere close to SSMS.

Re:Why you should never use MongoDB (2013) by lmm on Monday August 15, 2016 @04:29PM (#12293163)
> And how would any of those problems be solved by using raw SQL strings or a document DB? That just moves the problems back into the schema or the data, where it's even harder to deal with.

I'm arguing for using a non-SQL interface. Either a structured binary query protocol (which leaves you shipping a lot of data around sure, but at least removes the constructing-and-parsing SQL overhead), or a map-reduce style setup where you can run your queries where the data is but in a first-class programming language.

Re:Why you should never use MongoDB (2013) by breischl on Monday August 15, 2016 @04:41PM (#12293253)
It seems to me that you're advocating changing implementation details (binary query protocol instead of SQL, map-reduce queries instead of sprocs) and claiming that it is somehow fundamentally different. But I don't see how that would be the case.

How is a binary query protocol fundamentally different than calling a sproc?

How is a map-reduce job in Javascript any different on the attributes you mentioned than ad-hoc SQL or a sproc?

Obviously map-reduce is a fundamentally different approach to data processing, but it seems to have similar traits in regards to source control, testability, etc.

Re:Why you should never use MongoDB (2013) by lmm on Monday August 15, 2016 @07:02PM (#12294175)
Binary query protocol is just a tweak, but it's a tweak that most RDBMSes are missing, and it matters for some workloads.

Switching to a model where you supply your own map-reduce or pipeline is a real shift, I think, from the DB as a framework that manages querying for you to more of a library/toolkit you can use to write your own computations. The indexed tables model is an incredibly effective compromise, but it's still a compromise - if you know specifically what you need to do, you can do it better.

Running a first-class programming language with full support for usual programming language tools is a major difference for developability, testability, libraries and so on. Deployment model depends on the datastore - plenty of non-SQL ones have room for improvement here - but I think the traditional RDBMS still has the worst of it.

Re:Why you should never use MongoDB (2013) by breischl on Tuesday August 16, 2016 @04:42PM (#12300489)
Huh, interesting. I wonder if this is down to us having used different RDBMSes?

Most of my experience has been with SQL Server, which I think does use a (mostly) binary wire protocol, at least when calling sprocs. It also has a pretty good query optimizer - I've spent a lot of time trying to beat it with hand-tuned queries and only come up with something better about 50% of the time. And there are a lot of tools for source controlling the DB scripting and testing everything. It's not hard to do unit test style runs that set up and tear down tables and DBs.

Has that not been your experience?

Re:Why you should never use MongoDB (2013) by lmm on Wednesday August 17, 2016 @07:01AM (#12303726)
> which I think does use a (mostly) binary wire protocol, at least when calling sprocs

Hmm. I'm used to invoking storedprocedures via "select mysproc(param1, param2, ...)" which still has to be formed into a string and then parsed on the DB side using the arbitrary-SQL parser (because there's no way for the DB to know a priori that it's not a "regular" query). Does SQL server have some special case binary protocol for invoking them directly?

> It also has a pretty good query optimizer - I've spent a lot of time trying to beat it with hand-tuned queries and only come up with something better about 50% of the time.

The query planner can usually run the best query possible with the indices that exist, sure. But you have to fit your calculation into this model of indices that are built on insert and everything else happening at query time. Or you go down the route of lazy materialized views that make use of other lazy materialized views, specifying indexing strategies... I mean I think you can ultimately express any data processing pipeline in a RDBMS if you try hard enough (though you have to use database-specific features that tend to be less-well supported by the ecosystem), but at some point it's easier to just have a first-class programming language that has access to the data, and write the code that you want to run.

> And there are a lot of tools for source controlling the DB scripting and testing everything. It's not hard to do unit test style runs that set up and tear down tables and DBs.

Up to a point. It's easy to end up with "unit" tests that take a second for each test, which mean it's not really practical to get good coverage of logic there.

In terms of source controlling and so on I guess the big problem is that you now have a distributed system written in two quite different technologies. So you've got to figure out a release and deployment process that handles both, and a lot of shops don't seem to bother. If you're already running a multi-language microservice architecture then this is probably a lot less of an issue.

Re:Why you should never use MongoDB (2013) by breischl on Wednesday August 17, 2016 @10:18AM (#12304866)
TBH I've never really looked at how TDS (the SQLServer wire protocol) works. From a code level, in ADO.NET you would create a query object, set the type to "sproc", set the name of the sproc, and attach parameters as objects. I bet the sproc name is going across as text, and maybe the param names, but that's probably it.

>>So you've got to figure out a release and deployment process that handles both, and a lot of shops don't seem to bother.

Yeah, that's true. Setting up something along the lines of Rails' migrations isn't really that hard, but many don't bother.

Re:Why you should never use MongoDB (2013) by dragonwriter on Monday August 15, 2016 @04:04PM (#12292996)
> > Or you could use stored procedures. Think of it as making your RDBMS into a microservice, if you like.

> The trouble is testability, versioning, deployment, and SQL just not being a pleasant language for expressing business logic.

Most of those, to the extent they are valid, are trouble with using stored procs in SQL for that purpose, but most RDBMSs support stored procs in languages other than SQL.

Re:Why you should never use MongoDB (2013) by lmm on Monday August 15, 2016 @04:25PM (#12293138)
Testability, versioning, deployment, IDE support and library support are still very much issues with non-SQL stored procedures.
Re:Why you should never use MongoDB (2013) by gaius on Monday August 15, 2016 @02:26PM (#12292366)
Indices are updated synchronously on every insert, slowing your writes, for the sake of transactional guarantees that most applications aren't written to take advantage of. Queries have to be passed over the wire as strings

Those are implementation details, not inherent properties of the relational model.

Re:Why you should never use MongoDB (2013) by EpicEng on Monday August 15, 2016 @06:45PM (#12294088)
If they're pervasive then it's irrelevant. Looking at this stuff from a purely academic viewpoint isn't useful to people who care about implementation details.
Re:Why you should never use MongoDB (2013) by dragonwriter on Monday August 15, 2016 @03:06PM (#12292655)
> And I don't know why there aren't RDBMSes without better query languages and schema definition languages, but there aren't

Well, better is subjective, but there are RDBMSs with languages other than SQL (e.g., Dataphor with its D4 language.)

Re:Why you should never use MongoDB (2013) by jdmichal on Monday August 15, 2016 @02:27PM (#12292382)
> You're assuming that you need to change things. Almost all big-data approaches work better when you abandon that and go for a log-structured model where you only ever append.

That depends on your loads. If you're write heavy, then yes. If you're read heavy, then you're adding extra work to find the current row out of all the appends. If you're read and write heavy, then get used to buying really expensive beefy machines and maybe sharding...