mysql

Mysql calculate row size for all tables

SELECT col_sizes.TABLE_SCHEMA, col_sizes.TABLE_NAME, SUM(col_sizes.col_size) AS EST_MAX_ROW_SIZE
FROM (
    SELECT 
        cols.TABLE_SCHEMA, 
        cols.TABLE_NAME, 
        cols.COLUMN_NAME,
        CASE cols.DATA_TYPE
            WHEN 'tinyint' THEN 1
            WHEN 'smallint' THEN 2
            WHEN 'mediumint' THEN 3
            WHEN 'int' THEN 4
            WHEN 'bigint' THEN 8
            WHEN 'float' THEN IF(cols.NUMERIC_PRECISION > 24, 8, 4)
            WHEN 'double' THEN 8
            WHEN 'decimal' THEN ((cols.NUMERIC_PRECISION - cols.NUMERIC_SCALE) DIV 9)*4  + (cols.NUMERIC_SCALE DIV 9)*4 + CEIL(MOD(cols.NUMERIC_PRECISION - cols.NUMERIC_SCALE,9)/2) + CEIL(MOD(cols.NUMERIC_SCALE,9)/2)
            WHEN 'bit' THEN (cols.NUMERIC_PRECISION + 7) DIV 8
            WHEN 'year' THEN 1
            WHEN 'date' THEN 3
            WHEN 'time' THEN 3 + CEIL(cols.DATETIME_PRECISION /2)
            WHEN 'datetime' THEN 5 + CEIL(cols.DATETIME_PRECISION /2)
            WHEN 'timestamp' THEN 4 + CEIL(cols.DATETIME_PRECISION /2)
            WHEN 'char' THEN cols.CHARACTER_OCTET_LENGTH
            WHEN 'binary' THEN cols.CHARACTER_OCTET_LENGTH
            WHEN 'varchar' THEN IF(cols.CHARACTER_OCTET_LENGTH > 255, 2, 1) + cols.CHARACTER_OCTET_LENGTH
            WHEN 'varbinary' THEN IF(cols.CHARACTER_OCTET_LENGTH > 255, 2, 1) + cols.CHARACTER_OCTET_LENGTH
            WHEN 'tinyblob' THEN 9
            WHEN 'tinytext' THEN 9
            WHEN 'blob' THEN 10
            WHEN 'text' THEN 10
            WHEN 'mediumblob' THEN 11
            WHEN 'mediumtext' THEN 11
            WHEN 'longblob' THEN 12
            WHEN 'longtext' THEN 12
            WHEN 'enum' THEN 2
            WHEN 'set' THEN 8
            ELSE 0
        END AS col_size
    FROM INFORMATION_SCHEMA.COLUMNS cols
) AS col_sizes
where TABLE_SCHEMA not in ( 'information_schema', 'sys', 'mysql','performance_schema' )
GROUP BY col_sizes.TABLE_SCHEMA, col_sizes.TABLE_NAME
admin

Share
Published by
admin

Recent Posts

How to back up and restore the ESXi host configuration

Original https://kb.vmware.com/s/article/2042141 Backing up ESXi host configuration data To synchronize the configuration changed with persistent…

12 месяцев ago

vCenter Converter Standalone download

vCenter Converter Standalone 6.6.0 download (далее…)

1 год ago

VMware remote console (VMRC) 12 download

VMware remote console (VMRC) 12.0.5 download Last version: VMware Remote Console 12.0.5  28 NOV 2023…

2 года ago

Mysql change date format in database

UPDATE DB SET column = DATE(STR_TO_DATE(column, '%Y-%d-%m')) WHERE DATE(STR_TO_DATE(column, '%d-%m-%Y')) <> '0000-00-00'

2 года ago

esxi debian lvm extend partition

echo 1 > /sys/class/block/sda/device/rescan #maybe run under root> sudo fdisk /dev/sda2 > d > 2…

2 года ago

SQL max/min length for all columns

First variant SELECT CONCAT(GROUP_CONCAT( CONCAT('(SELECT \'',COLUMN_NAME,'\' AS `column`, MAX(CHAR_LENGTH(`',COLUMN_NAME,'`)) AS `max_length`, MIN(CHAR_LENGTH(`',COLUMN_NAME,'`)) AS `min_length` ',…

2 года ago