You can also change values using new
. You just have to use not after
but before
trigger.
delimiter $$
create trigger increment
before update on T1
begin
if new.C1=0 then
set new.c2 = new.c2 +1;
end if;
end $$
delimiter ;
I think I have a plausible explanation you find very intriguing.
When you loaded the MyISAM table, only one index got loaded into the .MYI
file in a lopsided manner.
Which index would that be ? THE PRIMARY KEY. Why ?
Indexes usually use BTREEs. They are designed to collect keys into a single BTREE node and balance the BTREE internally until the BTREE is full. On the insert into the full node, the full tree node is split and the keys inside are divided.
Most often a BTREE node will split is when you load the keys in order. For proof, look at the worst case BTREE --- the balanced binary tree.
I have several posts in the DBA STackExchange where I mention how a balanced binary only has node with one key. I also mention how a leaf pages must rebalance about 45% of the time when inserting a new key. Here are those posts:
My working theory is that random inserts into the table may actually make the .MYI
smaller by prevent tree node splits as much as possible.
In order to make this happen, you will have to something quite unusual. Ready for this ?
ALTER TABLE generic_dummy_table_name ORDER BY datetime;
or
ALTER TABLE generic_dummy_table_name ORDER BY user,datetime;
That right, you can reorder the physical rows of the table. This may make the indexes a different size by inducing BTREE splits on another index.
Try reordering the table. Then, mysqldump it and reload it. You may find that the .MYI
may get smaller or bigger. You cannot really predict it.
Next time, try reloading the MyISAM table with a very large bulk insert buffer.
Just run
SET GLOBAL bulk_insert_buffer_size = 1024 * 1024 * 1024;
then connect to mysql and reload the mysqldump.
GIVE IT A TRY !!!
Best Answer
I think you have your column data-type on non numeric format. if your data type is
CHAR
(orVARCHAR
) type it would select 9 as your max number.If you change your datatype for the column to
INT
, your problem should be resolved.