We are excited to announce that Vitess now supports recursive Common Table Expressions (CTEs), marking another significant step in our journey to fully align with MySQL’s capabilities. Recursive CTEs, often a critical feature for complex query handling, allow for the execution of recursive queries within a single CTE. This addition brings more flexibility and power to developers using Vitess, especially those working with distributed databases. One of the key challenges in implementing recursive CTEs within a sharded environment is managing the distribution of data across multiple shards.
This is the second part of a two-articles series. In the first part, we introduced the Common Table Expression (CTE), a new feature available on MySQL 8.0 as well as Percona Server for MySQL 8.0. In this article, we’ll present the Recursive Common Table Expression. SQL is generally poor at recursive structures, but it is now possible on MySQL to write recursive queries. Before MySQL 8.0, recursion was possible only by creating stored routines.
What is a Recursive Common Table Expression?
A recursive CTE is one having a subquery that refers to its own name. It is particularly useful in the following cases:
- To generate series
- Hierarchical or tree-structured data traversal
This blog is the first part of a two-articles series. In this article, I’m going to introduce the Common Table Expression (CTE), a new feature available on MySQL 8.0, as well as Percona Server for MySQL 8.
What is a Common Table Expression?
We can define a CTE as an alternative to a derived table. In a small way, CTE simplifies complex joins and subqueries, improving the readability of the queries. CTE is part of ANSI SQL 99 and was introduced in MySQL 8.0.1. The same feature is available even on Percona Server for MySQL 8.0.
The main reasons for using CTE are:
- Better readability of the queries
- Can be referenced multiple times in the same query
- Improved performance
- A valid alternative to a VIEW, if your user cannot create VIEWs
- Easier chaining of multiple CTE …
JSON (JavaScript Object Notation) is a popular way for moving data between various systems, including databases. Starting with 5.7 MySQL implemented a native JSON data type and a set of JSON functions that allows you to perform operations on JSON values.
I am happy that the MySQL team is, during the last years, blogging about each major feature that MySQL Server is getting; for example, the series on Recursive Common Table Expressions. Being extremely busy myself, …
[Read more]
There is a new feature in the MariaDB 10 Beta which caught my
eye: support for returning a result set on delete.
With a 'regular' DELETE operation you only get to know the number
of affected rows. To get more info or actions you have to use a
trigger or a foreign key. Anoter posibility is doing a SELECT and
then a DELETE and with the correct transaction isolation a
transactional support this will work.
With the support for the RETURNING keyword this has become easier
to do and it will probably bennefit performance and save you a
few roundtrips and a few lines of code.
There is already support for RETURNING in PostgreSQL. And
PostgreSQL has an other nifty feature for which RETURNING really
helps: CTE or common table expressions or the WITH keyword. I
really hope to see CTE support in MySQL or MariaDB some
day.
…