News for hackers. Stuff that matters.
Re:Expressive Power of SQL (2003) [pdf] by numbsafari on Friday November 03, 2017 @10:22AM (#15619384)
Interesting to note that neither BigQuery, nor Apache Presto (and therefore AWS Athena), support recursive CTEs.

However, most other DBs do (e.g. Postgres, MS SQL, MySQL 8.0, MariaDB 10.2, Oracle, etc.).

Which is disappointing, given how powerful BQ and Presto/Athena are for startups.

Re:Expressive Power of SQL (2003) [pdf] by dspillett on Friday November 03, 2017 @10:31AM (#15619438)
Be careful with CTEs with regard to performance, some SQL DBs can optimise by pushing predicates through to the inner queries, where for some (postgres being the one example that I know but there are probably others) a CTE presents an optimisation fence.
Re:Expressive Power of SQL (2003) [pdf] by MarkusWinand on Friday November 03, 2017 @12:41PM (#15620471)
PostgreSQL being the one noteworthy: http://modern-sql.com/feature/with/performance
Re:Expressive Power of SQL (2003) [pdf] by nerdponx on Friday November 03, 2017 @12:54PM (#15620561)
I never understood this. Why can't CTEs be transparently compiled into subqueries?
Re:Expressive Power of SQL (2003) [pdf] by dspillett on Friday November 03, 2017 @01:09PM (#15620683)
There is plenty of discussion about it out there (search for "postgres cte optimisation fence") including official word.

Note though that simply replacing CTE references with appropriate sub-queries simply won't work in the recursive case, and in some cases where a CTE is referred to multiple times the result may be an even less optimal query plan.

Re:Expressive Power of SQL (2003) [pdf] by MarkusWinand on Friday November 03, 2017 @12:42PM (#15620473)
Not to forget SQLite: https://sqlite.org/lang_with.html
Re:Expressive Power of SQL (2003) [pdf] by makapuf on Friday November 03, 2017 @11:39AM (#15619985)
Just so you know, CTE means in this context Common Table Expression. This StackOverflow question [0] can explain a bit about it. Can be used as pseudo-views to clarify sql code.

[0] https://stackoverflow.com/questions/4740748/when-to-use-comm...

Re:Expressive Power of SQL (2003) [pdf] by kwillets on Friday November 03, 2017 @04:02PM (#15621841)
To be fair, neither does Vertica. The big data warehouses are expecting fairly flat predigested fact tables.
Re:Expressive Power of SQL (2003) [pdf] by __coaxialcabal on Friday November 03, 2017 @06:51PM (#15622746)
Recursive CTEs have been implemented as UDx in Vertica, although possibly not available publicly. This is where you need to look carefully at can vs. should and carefully consider what you are trying to accomplish.
Re:Expressive Power of SQL (2003) [pdf] by __coaxialcabal on Friday November 03, 2017 @01:19PM (#15620753)
Recursive CTEs are significantly more difficult to implement in an MPP platform than SMP.
Re:Expressive Power of SQL (2003) [pdf] by YeGoblynQueenne on Friday November 03, 2017 @08:27PM (#15623154)
>> However, logicians proved it long time ago that first-order logic, and thus relational calculus, cannot compare cardinalities of relations, and yet we have a very simple SQL query doing precisely that.

I'm not sure what the bit about comparing cardinalities refers to. I think it relates to Trakhtenbrot's theorem, or the Löwenheim–Skolem theorem, but I'd appreciate it if someone clarified this.

As it is, my intuition is that the result mentioned is for either finite or infinite relations, or in any case for some broad case of unrestricted sentences (any formula in any language), whereas there are restricted cases where it doesn't hold (sort of like satisfiability).

Like I say, if anyone knows what this refers to, please speak up.

____________________

[1] https://en.wikipedia.org/wiki/Trakhtenbrot%27s_theorem

[2] https://en.wikipedia.org/wiki/L%C3%B6wenheim%E2%80%93Skolem_...

Re:Expressive Power of SQL (2003) [pdf] by domparise on Friday November 03, 2017 @10:27AM (#15619414)
Isn't SQL Turing complete? So imo the question of "how expressive is SQL" is really just "how expressive can SQL be with reasonably useful performance".
Re:Expressive Power of SQL (2003) [pdf] by corpMaverick on Friday November 03, 2017 @10:43AM (#15619521)
From what I can understand (barely) The paper tries to determine if some of the new(2003) SQL3 extensions were really needed.

From the answers here https://stackoverflow.com/questions/900055/is-sql-or-even-ts...

It seems that SQL92 was not Turing complete but it became turing complete later on. Possibly by the same extensions added in SQL3.

Re:Expressive Power of SQL (2003) [pdf] by MarkusWinand on Friday November 03, 2017 @12:43PM (#15620483)
The mentioned proof is confirming SQL:2003.

See also: https://wiki.postgresql.org/wiki/Cyclic_Tag_System

Re:Expressive Power of SQL (2003) [pdf] by lmkg on Friday November 03, 2017 @10:44AM (#15619534)
I don't think that vanilla SQL defined in older versions of the standard is actually Turing-complete. Most commercial releases included features that made it Turing complete, and my understanding is that the most recent standard includes enough from these features that it's now Turing-complete.
Re:Expressive Power of SQL (2003) [pdf] by mhd on Friday November 03, 2017 @10:56AM (#15619622)
That reminds me of some horrible datbase designs I've seen, where people too enamored with FSMs/petri nets etc. tried to put the "code" into tables…
Re:Expressive Power of SQL (2003) [pdf] by Kenji on Friday November 03, 2017 @03:36PM (#15621698)
Sounds like the stuff my code refactoring nightmares are made of. The opposite case is funny too though: I've seen people who fetched and deserialized the entire SQL table and then manually SELECTed by looping over it with a foreach loop and picking the right record =)

They even had their own custom logic to do table JOINs. It involved fetching and deserializing both entire tables with SELECT *, of course.

Relational calculus at its finest, me gusta.

Re:Expressive Power of SQL (2003) [pdf] by kafkaesq on Friday November 03, 2017 @01:07PM (#15620659)
Isn't SQL Turing complete?

Even if it is -- "turing complete" != "expressive".

They're rather different beasties, in fact.