문제

How can I calculate the size in Bytes (MB, GB) used by a subset of rows in a MySQL table. The use case is to determine the footprint of a user in the database. So the idea is to select all rows that belong to a user in a table a calculate the size of those rows including their indices (indexes?)

I found something like this, but this only gives me the size of the whole table:

SELECT table_schema "Data Base Name", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" 
FROM information_schema.TABLES GROUP BY table_schema ;

I would really appreciate an answer to that.

도움이 되었습니까?

해결책

I think the easiest way to do this is to get an estimate. I assume that you can count the number of rows in the table 'owned' by that user, and from that and the total number of rows you can get the percentage of rows 'owned' by that user. Apply that percentage to the total size of the table and you have your estimate.

If you try for anything more accurate you are unlikely to achieve it without a lot of hard work, and it will probably involve making estimate about other things, so I'd say just go with the estimate. If I was asked to do this, I'd say that it wouldn't be possible to be accurate but that a reasonable estimate could be made, is that good enough....

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top