I saw a new feature Invisible Columns in MariaDB 10.3.x. What are practical use cases for DBA and web developer? When to use this feature?
Columns can be given an
INVISIBLE
attribute in aCREATE TABLE
orALTER
statement. These columns will then not be listed in the results
TABLE
of aSELECT *
statement, nor do they need to be assigned a value in an
INSERT
statement, unlessINSERT
explicitly mentions them by name.Since
SELECT *
does not return the invisible columns, new tables or
views created in this manner will have no trace of the invisible
columns. If specifically referenced in theSELECT
statement, the
columns will be brought into the view/new table, but theINVISIBLE
attribute will not.Invisible columns can be declared as
NOT NULL
, but then require a
DEFAULT
value
Best Answer
This is of course not standard SQL, and generally goofy. Instead follow best practices,
INVISIBLE
columns.SELECT *
in production code.MariaDB's
INVISIBLE
ColumnsIt seems that the intention is to permit MariaDB users to continue to use
SELECT *
which is almost always against a DBA's best practices. So now you can useSELECT *
, and then add to the table without mutating the result returned bySELECT *
.And you have an export that dumps
users
withSELECT *
. Later if you wish to add a column, you can mark it asINVISIBLE
and maintain the resultPost-
ADD COLUMN
you're still hilariously safe without learning that no one in their right mind would useSELECT *
for in that case.Though only one type of invisibility is exposed to the user, MariaDB internally has four different types of invisibility. For more information see, MDEV-10177 Invisible columns. Invisibility also effects
INSERT
, find more information on the ticketOther Databases
As an aside, Oracle calls this feature
INVISIBLE
, and DB2 calls itIMPLICITLY HIDDEN
. In other dialects of SQL where this isn't supported you would just create aVIEW
,