5 ms·
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
by numbsafari 9y ago
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.
- dspillett 9y agoBe 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.
- MarkusWinand 9y agoPostgreSQL being the one noteworthy: http://modern-sql.com/feature/with/performance http://modern-sql.com/feature/with/performance
- nerdponx 9y agoI never understood this. Why can't CTEs be transparently compiled into subqueries?
- dspillett 9y agoThere 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.
- deleted 9y ago[deleted]
- makapuf 9y agoJust 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-common-table-expression-cte#4740800 https://stackoverflow.com/questions/4740748/when-to-use-comm...
- MarkusWinand 9y agoNot to forget SQLite: https://sqlite.org/lang_with.html https://sqlite.org/lang_with.html
- __coaxialcabal 9y agoRecursive CTEs are significantly more difficult to implement in an MPP platform than SMP.
- kwillets 9y agoTo be fair, neither does Vertica. The big data warehouses are expecting fairly flat predigested fact tables.
- __coaxialcabal 9y agoRecursive 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.