MySQL - universal way of getting approx. row size in bytes -
ok, won't mad if nobody wants me nonsense, wanted have way approximate row row byte size of table in mysql console (well i'm using phpmyadmins sql window).
the inner query reads desired table columns schema , group_concats them a statement, while adding char_length() function every column name. did not find better way, using separator this, separator comes first after first element, add 2 nonsense elements : "empty" @ beginning , "zzempty" @ end. thoses stripped of replace later.
the best part is, think code want, problem is, results fetched not displayed.
what easiest way results fetched prepared statement? way results put them table?
set @query = concat('select ', (select replace(group_concat( column_name order case when column_name="empty" 0 when column_name = 'zzempty'then 99 else 1 end, column_name separator '`) + char_length(`'), 'empty`) + ', '') (select 'empty' column_name, '1' id union select column_name, 1 id information_schema.columns table_schema = 'db_name' , table_name = 'table_name' union select 'zzempty' column_name, '1' id ) t1 group id),' `table_name`'); set @query2 = replace( @query, '+ char_length(`zzempty', '') ; prepare stmt @query2; execute stmt ;
in fact, think there must easier way row size, did not find any.
it's easier ask mysql
it, using show table status
statement:
mysql> show table status name='apirequest'\g *************************** 1. row *************************** name: apirequest engine: innodb version: 10 row_format: compact rows: 105 avg_row_length: 1872 data_length: 196608 max_data_length: 0 index_length: 16384 data_free: 2520776704 auto_increment: 114 create_time: 2015-05-29 13:00:13 update_time: null check_time: null collation: utf8_unicode_ci checksum: null create_options: comment: 1 row in set (0.00 sec)
Comments
Post a Comment