Comments on: Looking out for max values in integer-based columns in MySQL https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/ Tue, 13 Feb 2024 17:25:08 +0000 hourly 1 https://wordpress.org/?v=6.5.2 By: Flimm https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7706873 Tue, 08 Jul 2014 11:47:33 +0000 https://www.percona.com/blog/?p=24354#comment-7706873 Another way to catch these problems is to pay attention to MySQL warnings, by logging them.

]]>
By: Yogesh Malik https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7701614 Tue, 08 Jul 2014 04:42:41 +0000 https://www.percona.com/blog/?p=24354#comment-7701614 Hi,

We also faced the same situations last year which we weren’t aware of and never expected but it happened and it took us one hour to identify the problem. It was embarrassing moment as service was down for almost 1 hour.

Thanks Matthew for more insight.

]]>
By: Fadi (itoctopus) https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7697093 Mon, 07 Jul 2014 22:10:37 +0000 https://www.percona.com/blog/?p=24354#comment-7697093 @r937,

Sorry – my bad. I seem to have skipped your second line in your original comment.

]]>
By: r937 https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7697080 Mon, 07 Jul 2014 22:07:06 +0000 https://www.percona.com/blog/?p=24354#comment-7697080 @Fadi — me? me confused? on the contrary, i was trying to point out that the number in parentheses is a red herring

http://en.wikipedia.org/wiki/Red_herring

“… something that misleads or distracts from the relevant or important issue”

]]>
By: Matthew Boehm https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7697018 Mon, 07 Jul 2014 22:01:13 +0000 https://www.percona.com/blog/?p=24354#comment-7697018 @Ike – You are correct in that the auto_increment values are available in information_schema. But, unfortunately, the current (or MAX) value of other non-A_I integer-based columns is not, so you must SELECT that directly from the table.

]]>
By: Fadi (itoctopus) https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7696220 Mon, 07 Jul 2014 20:50:46 +0000 https://www.percona.com/blog/?p=24354#comment-7696220 @r937,

I think you’re confusing the x in INT(x) for the number of bits/bytes. You can read more about this here: http://stackoverflow.com/questions/7552223/int11-vs-intanything-else

@Matthew,

You are probably the first person I know of that uses Go for something that is not experimental. Oh, and congratulations on your new post. I love this blog and I visit it regularly.

]]>
By: r937 https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7693273 Mon, 07 Jul 2014 16:39:11 +0000 https://www.percona.com/blog/?p=24354#comment-7693273 you say at the outset that you wanted to change all INT(11) to INT(10) UNSIGNED

sweet, but the numbers in parentheses are huge red herrings, especially as you seem to want to make the number smaller by 1

you could just as easily have said INT(937) UNSIGNED for all the difference it makes

]]>
By: Ike Walker https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7692745 Mon, 07 Jul 2014 15:43:11 +0000 https://www.percona.com/blog/?p=24354#comment-7692745 I use common_schema for this. If you have common_schema installed, the auto_increment_columns view exposes this data and is simpler to work with than information_schema.

I also blogged about this a while back: http://mechanics.flite.com/blog/2012/07/16/monitoring-auto-increment-capacity-in-mysql/

]]>
By: Charl Retief https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7692155 Mon, 07 Jul 2014 15:04:29 +0000 https://www.percona.com/blog/?p=24354#comment-7692155 Matthew,

You are absolute correct, the “Procedure Analyse” route is horribly slow due to the full table scans. Definitely not something you want to use on production systems. You method is more suited for your described work case.

]]>
By: Matthew Boehm https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7691648 Mon, 07 Jul 2014 14:25:23 +0000 https://www.percona.com/blog/?p=24354#comment-7691648 Hi Charl,
Yes, you could certainly do that. However, your procedure would still require external intervention in the form of a script to execute the SP and parse the result. Also, your SP is doing “SELECT *” which will certainly incur a full-table-scan. With my script, only the relevant columns are SELECT’ed and in the case of that column being indexed, won’t incur the penalty.

Additionally, in the environment for my client, with 200+ MySQL servers, deploying a single binary to a central “admin server” and executing multiple copies was far easier than having to deploy a stored procedure to each system. Going the SP route would constitute “a change” and thus the client’s change management policies would have to be followed with approvals and meetings etc etc. My script wasn’t a change and thus easier to be implemented.

]]>
By: Charl Retief https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7691039 Mon, 07 Jul 2014 13:40:43 +0000 https://www.percona.com/blog/?p=24354#comment-7691039 On you first blog post, let me make my first ever comment.

On this topic it is also worth mentioning that MySQL has this obscure feature it called “Procedure Analyse”. It gives you current data type usage min and max values, null frequency ect. as well as optimal suggested field size.
http://dev.mysql.com/doc/refman/5.6/en/procedure-analyse.html

You could very easily use this to get this information without any external scripting. Like:
SELECT * FROM table1 PROCEDURE ANALYSE(10, 2000);

Or this stored proc that does it for a whole db:

CREATE PROCEDURE table_field_size_analyse(IN $database VARCHAR(255))
BEGIN

DECLARE $table_name VARCHAR(255);

DECLARE $table_cursor CURSOR FOR SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = $database;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET $table_name = NULL;

OPEN $table_cursor;
table_loop: LOOP

FETCH $table_cursor INTO $table_name;

IF $table_name IS NULL
THEN
LEAVE table_loop;
END IF;

SET @dsql = CONCAT(‘SELECT * FROM ', $database, '.', $table_name , ' PROCEDURE ANALYSE(10, 2000);’);

PREPARE stmt1 FROM @dsql;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;

END LOOP;
CLOSE $table_cursor;

END

]]>
By: Shlomi Noach https://www.percona.com/blog/looking-out-for-max-values-in-integer-based-columns-in-mysql/#comment-7690394 Mon, 07 Jul 2014 12:18:36 +0000 https://www.percona.com/blog/?p=24354#comment-7690394 Please also consider using common_schema’s auto_increment_columns view: https://common-schema.googlecode.com/svn/trunk/common_schema/doc/html/auto_increment_columns.html
or just use this query: http://code.openark.org/blog/mysql/checking-for-auto_increment-capacity-with-single-query

or otherwise use this openark-kit tool: http://openarkkit.googlecode.com/svn/trunk/openarkkit/doc/html/oak-show-limits.html

We’re using the common_schema view when monitoring our servers. We’re checking this view on a couple slaves (they all resolve the same obviously, and we don’t want to do I_S queries on the master if we don’t have to). We have threshold alerts on the AUTO_INCREMENT capacity and live quietly ever after.

]]>