Comments - Generated (Virtual and Persistent/Stored) Columns
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.
This article quotes some restrictions existing in other DBMSs but does not say that MariaDB has important limitations not existing in other products. For instances the SQL Server computed columns are described as:
A computed column is computed from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, and any combination of these connected by one or more operators. The expression cannot be a subquery.
Which means that MS computed columns have not some major MariaDB virtual column restrictions:
All these limitation are bad and really limit the interest of virtual columns. Limitation on constant and expression length are not justifiable.
About the limitation on deterministic expressions, this is simply the necessity of this feature that is questionnable. Indeed, a feature is necessary if it enables to do things that cannot be done by other mean. For instance:
This is Ok, however the same result can be obtained with the table:
with the query:
Therefore, virtual columns appears as just a query wording facility without bringing a real new concept.
Things would be different if non deterministic expressions would be accepted. Firstly it would make possible to add useful things such as an AGE column returning the same result than saying:
But even more, it would make possible to do things that are not possible by other means:
A query such as:
can return result such as:
This apparently strange result comes from the fact that the rand() function is called on each appearance in the query. However, if it were possible to do;
Providing that a column value is evaluated only once per row, as many DBMSs do, the query:
would never return rows with val >= 0.5.
Of course restrictions such as not using this virtual column for indexing or constraint would apply.
"Their value can be a not deterministic function, except if use in an index or a constraint."
In 10.1.6 (at least), you can use non-deterministic functions, but apparently the 252 character limitation still exists.
I'd show you, but I'm frustrated with the UI here. How did you get the <pre></pre> to work in your comment?
Let's try some <code>:
Ah, that's better. :-)
(You guys REALLY need an "Edit" button...)