Hey Vinicius,
The show table status memory
command may be useful here. With 90% nulls on all eligible sparse columns, and 0
as the nonnull value inserted, I’m seeing
memsql> show table status memory\G
*************************** 1. row ***************************
Name: s
Rows: 1000000
Total Memory Use: 198198832
Row Structs: 132382720
Allocated Offrow Struct Memory: 17816112
Requested Offrow Struct Memory: 14400000
Deleted Version Row Structs: 0
HTNodes: 0
Indexes: 32000000
Variable Allocator: 33816112
*************************** 2. row ***************************
Name: t
Rows: 1000000
Total Memory Use: 313027584
Row Structs: 265027584
Allocated Offrow Struct Memory: NULL
Requested Offrow Struct Memory: NULL
Deleted Version Row Structs: 0
HTNodes: 0
Indexes: 32000000
Variable Allocator: 16000000
which is about a 1.58 compression ratio. I’m interested what the command reports to you. Inserting larger varchar values will move this ratio closer to 1.
CREATE TABLE `t` (
`id` varchar(14) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tipo` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`nome` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`fantasia` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`email` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`telefone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`logradouro` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`numero` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`complemento` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`bairro` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`municipio` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`uf` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`cep` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`abertura` date DEFAULT NULL,
`natureza_juridica` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`situacao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`data_situacao` date DEFAULT NULL,
`situacao_especial` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`motivo_situacao_especial` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`data_situacao_especial` date DEFAULT NULL,
`capital_social` decimal(30,2) DEFAULT NULL,
`efr` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`ultima_atualizacao` datetime NOT NULL,
`extra` JSON COLLATE utf8_bin DEFAULT NULL,
`rand` float DEFAULT NULL
/*!90618 , SHARD KEY () */
) /*!90623 AUTOSTATS_CARDINALITY_MODE=OFF, AUTOSTATS_HISTOGRAM_MODE=OFF */ /*!90623 SQL_MODE='STRICT_ALL_TABLES' */
CREATE TABLE `s` (
`id` varchar(14) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`tipo` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`nome` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`fantasia` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`email` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`telefone` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`logradouro` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`numero` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`complemento` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`bairro` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`municipio` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`uf` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`cep` varchar(8) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`abertura` date DEFAULT NULL SPARSE,
`natureza_juridica` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`situacao` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`data_situacao` date DEFAULT NULL SPARSE,
`situacao_especial` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`motivo_situacao_especial` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`data_situacao_especial` date DEFAULT NULL SPARSE,
`capital_social` decimal(30,2) DEFAULT NULL,
`efr` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL SPARSE,
`ultima_atualizacao` datetime NOT NULL,
`extra` JSON COLLATE utf8_bin DEFAULT NULL,
`rand` float DEFAULT NULL SPARSE
/*!90618 , SHARD KEY () */
) /*!90623 AUTOSTATS_CARDINALITY_MODE=OFF, AUTOSTATS_HISTOGRAM_MODE=OFF */ /*!90623 SQL_MODE='STRICT_ALL_TABLES' */