It is somewhat wrong that SQL databases will execute whatever crap unindexed bloated query you happen to send to them without ever questioning your lack of senses.

Reply to this note

Please Login to reply.

Discussion

That would be a great AI uses case. "Pardon me, Human, but that is a stupid inefficient query".

Imagine if the db gives you an error message: excuse me sir, this query sucks and I won't run it. Try again n00b

Something like that would be ideal.

That’s a weird way of stating it, but do you mean that SQL servers can’t execute arbitrary queries, especially if the database is big and there are no indexes to support the query? If that’s what you mean you’re obviously correct.

The part about “questioning your lack of senses” is a bit confusing.

Who is doing the questioning?

Yes, that's what I mean. The database is doing the questioning.

Some databases have ways to block non-indexed queries. https://www.mongodb.com/docs/manual/reference/parameters/#param.notablescan

I generally think it's a mistake for SQL (and similar) to have a default query auto-planner. I would rather write something like 'take this index, filter for this, pick these fields, then join,..." - basically specifying the query plan myself. Too many times I got bitten by the planner using the wrong index. It's difficult to figure out & prevent, and sometimes query planner changes its mind for some runtime reasons (obviously always in production at 2am ).

What would you have them do instead?

This is why I like exposing through controlled stored procedures for the most part and setting resource limits as opposed to "indefinite time or until i run out of temp space thrashing disks for more swap space" #[0]

Would efficiency take a hit if the DB has to analyze the query efficiency first?