This is a read-only copy of the MariaDB Knowledgebase generated on 2024-12-22. For the latest, interactive version please visit https://mariadb.com/kb/.

Colonne Dinamiche in MariaDB 10

MariaDB starting with 10.0.1

In MariaDB 10 le Colonne Dinamiche avranno i seguenti miglioramenti.

Supporto ai nomi

Ovunque si usassero i numeri per riferirsi alle colonne, sarà ora possibile utilizzare le stringhe:

  • Creare un record di una Colonna Dinamica:
COLUMN_CREATE("int", -1212 as int, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char);
  • Alterare un record di una Colonna Dinamica (rimuovere la colonna chiamata "int" e aggiungerne una chiamata "intint"):
COLUMN_ADD(dynamiccolumns, "int", NULL, "intint", 12);
  • quando si cambia formato (da quello numerico a quello con i nomi):
COLUMN_ADD(COLUMN_CREATE(1,"string"), "1", NULL, "int", 12);
  • verificare se una colonna esiste
COLUMN_EXISTS(dynamic_column, "column1");
  • leggere il valore di una colonna:
COLUMN_GET(dynstr, "column1" as char(10));

Comportamenti modificati

  • L'output della lista delle colonne ora contiene le virgolette:
select column_list(column_create(1, 22, 2, 23));
+------------------------------------------+
| column_list(column_create(1, 22, 2, 23)) |
+------------------------------------------+
| `1`,`2`                                  |
+------------------------------------------+
select column_list(column_create('column1', 22, 'column2', 23)); 
+----------------------------------------------------------+
| column_list(column_create('column1', 22, 'column2', 23)) |
+----------------------------------------------------------+
| `column1`,`column2`                                      |
+----------------------------------------------------------+
  • L'interpretazione dei nomi delle colonne è stata modificata in modo che la stringa non sia più convertita in numero. Perciò alcuni trucchi "magici" non funzionano più: ad esempio "1test" e "1" ora sono trattati come nomi diversi:
select column_list(column_add(column_create('1a', 22), '1b', 23));
+------------------------------------------------------------+
| column_list(column_add(column_create('1a', 22), '1b', 23)) |
+------------------------------------------------------------+
| `1a`,`1b`                                                  |
+------------------------------------------------------------+
  • Vecchio comportamento:
select column_list(column_add(column_create('1a', 22), '1b', 23));
+------------------------------------------------------------+
| column_list(column_add(column_create('1a', 22), '1b', 23)) |
+------------------------------------------------------------+
| 1                                                          |
+------------------------------------------------------------+

Nuove funzioni

Le seguenti nuove funzioni sono state aggiunte alle Colonne Dinamiche in MariaDB 10

COLUMN_CHECK

Questa funzione verifica l'integrità di una colonna. Quando incontra un'anomalia non genera errori di formato illegale, ma restituisce falso. Inoltre controlla l'integrità in modo più approfondito e trova errori nelle strutture interne delle Colonne Dinamiche, che non possono essere trovati con le altre funzioni.

select column_check(column_create('column1', 22));
+--------------------------------------------+
| column_check(column_create('column1', 22)) |
+--------------------------------------------+
|                                          1 |
+--------------------------------------------+
select column_check('abracadabra');
+-----------------------------+
| column_check('abracadabra') |
+-----------------------------+
|                           0 |
+-----------------------------+

COLUMN_JSON

Questa funzione converte i record delle colonne dinamiche in oggetti JSON.

select column_json(column_create('column1', 1, 'column2', "two"));
+------------------------------------------------------------+
| column_json(column_create('column1', 1, 'column2', "two")) |
+------------------------------------------------------------+
| {"column1":1,"column2":"two"}                          |
+------------------------------------------------------------+

Other changes

  • All API functions has prefix mariadb_dyncol_ (old prefix dynamic_column_ is depricated
  • API changed to be able to work with the new format (*_named functions).
  • Removed 'delete' function because deleting could be done by adding NULL value.
  • 'Time' and 'datetime' in the new format are stored without microseconds if they are 0.
  • New function added to API (except that two which are representing SQL level functions):
    • 'Unpack' the dynamic columns content to an arrays of values and names.
    • 3 functions to get any column value as string, integer (long long) or floating point (double).
  • New type of "dynamic column" row added on the API level (in SQL level output it is a string but if you use dynamic column functions to construct object it will be added as dynamic column value) which allow to add dynamic columns inside dynamic columns. JSON function represent such recursive constructions correctly but limit depth of representation as current implementation limit (internally depth of dynamic columns embedding is not limited).

Interface with Cassandra

Some internal changes were added to dynamic columns to allow them to serve as an interface to Apache Cassandra dynamic columns. The Cassandra engine may pack all columns which were not mentioned in the MariaDB interface table definition and even bring chages in the dynamic column contents back to the cassandra columns family (the table analog in cassandra).

See Also

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.