Repository navigation
Recommend INT → BIGINT for AUTO_INCREMENT only when nearing capacity (headroom heuristic), not as a blanket rule
#479
nima1024m
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Summary
BIGINTpurely because a PK isINT(10), irrespective of actual usage or growth.Current behavior (observed)
Detection: Sees
INT(10)on a PK and recommendsBIGINT, regardless of row counts or insert rates.Effect: Users run:
…doubling PK and secondary index width without practical benefit on small/medium tables.
Why a blanket upgrade can hurt
ALTER TABLE ... MODIFYtypically rebuilds data; needs time, IOPS, and free space.Proposed solution: Headroom-based heuristic
1) Ignore display width
Treat
INT(10)the same asINT; width(10)is cosmetic and not capacity.2) Measure usage (capacity headroom)
Prefer metadata that exposes current
AUTO_INCREMENTand maximum representable value (by type + signedness):Fallback when
sysis not available (mind cached stats):3) Threshold-driven recommendation
usage_ratio ≥ threshold(e.g., 90%) or projected inserts will exhaust within N months, recommend upgrading to the next wider integer (usuallyBIGINT UNSIGNEDfor monotonic PKs).4) Extend to all integer widths
Apply the same logic across
TINYINT→SMALLINT→MEDIUMINT→INT→BIGINT.Only escalate when the forecast indicates exhaustion within the configured horizon.
Example
users.idINTINTevents.idINTBIGINTOnly the second is flagged—raising trust and avoiding needless DDL.
Suggested defaults
90%(configurable:50–99%)3 months(configurable:1–12 months)UNSIGNEDfor monotonic PKs to maximize rangeBIGINT UNSIGNED NOT NULL(when upgrading a monotonic PK)UX copy (examples)
Actionable (upgrade):
Informational (no change):
Acceptance criteria
Do not recommend
INT→BIGINTunless:usage_ratio ≥ threshold, orEach recommendation shows current value, max, usage %, forecast, and why.
Settings expose:
Telemetry records accept/ignore to refine defaults over time.
Implementation notes
Data sources
sys.schema_auto_increment_columns(MySQL 8+).information_schema.tables.auto_incrementwith fresh stats.Signed vs. unsigned
INTmax2,147,483,647;INT UNSIGNEDmax4,294,967,295).Operational guidance
ALGORITHM=INPLACE/LOCK=NONEwhere supported, but still expect copy-like behavior for type change.Edge cases
AUTO_INCREMENTrather thanMAX(id)to assess risk.AUTO_INCREMENT: Skip this rule.sysviews; degrade gracefully.Alternatives considered
Benefits
Closing
Kind regards,
Nima
All reactions