![]() | |
#11
| |||
| |||
|
|
I just had this sinking feeling... While the ALTER TABLE command is in progress, should clients be stopped from doing inserts into that table? because.. they are!!!! |
#12
| |||
| |||
|
#13
| |||
| |||
|
|
can I create an alter table and add three indices all at one? so rather than: ALTER TABLE MyTable ADD INDEX (a); ALTER TABLE MyTable ADD INDEX (b); ALTER TABLE MyTable ADD INDEX (c); Can this be done? ALTER TABLE MyTable ADD INDEX (a), (b), (c); |
#14
| |||
| |||
|
#15
| |||
| |||
|
|
I just had this sinking feeling... While the ALTER TABLE command is in progress, should clients be stopped from doing inserts into that table? because.. they are!!!! |
#16
| |||
| |||
|
|
Well I looked at the SQL and the WHERE statements and I can see that these indexes are necessary. (My table has 12.5 Million Rows at the moment.) The insert still seems quite fast, and the application lag that I was experiencing before adding these indexes is GONE! Yay. |
#17
| |||
| |||
|
|
I just had this sinking feeling... While the ALTER TABLE command is in progress, should clients be stopped from doing inserts into that table? because.. they are!!!! If the table before and after the ALTER TABLE is acceptable to your application (as would be the case for adding/deleting indexes), you're fine (MySQL table locking will handle it), unless the applications are so real-time that a locked table pause to rebuild an index is unacceptable. (For example, if your client is running your heart pacemaker, be careful.) If you are renaming or deleting a column used by the application and intend to fix the application to no longer use that column, yes, you need to stop your clients and fix them. If the number or order of columns is changing, this may break your SQL. One way to avoid this is to program defensively. In INSERT sql, list the columns: INSERT INTO foo (bar, baz, name) VALUES (99, 12, 'George'); NOT INSERT INTO foo VALUES (99, 12, 'George'); which will break if someone adds a 4th column. |
|
Don't use SELECT * FROM ...; . Name the columns. This protects you against problems when adding or re-arranging the order of the columns. |
#18
| |||
| |||
|
|
If the number or order of columns is changing, this may break your SQL. One way to avoid this is to program defensively. In INSERT sql, list the columns: INSERT INTO foo (bar, baz, name) VALUES (99, 12, 'George'); NOT INSERT INTO foo VALUES (99, 12, 'George'); which will break if someone adds a 4th column. well will it? |
|
Again, if using - say - PHP the data is orgainised in a field name indexed associative array, so it doesn't matter what the order is if you use the indices to access it. |
#19
| |||
| |||
|
|
Gordon Burditt wrote: I just had this sinking feeling... While the ALTER TABLE command is in progress, should clients be stopped from doing inserts into that table? because.. they are!!!! If the table before and after the ALTER TABLE is acceptable to your application (as would be the case for adding/deleting indexes), you're fine (MySQL table locking will handle it), unless the applications are so real-time that a locked table pause to rebuild an index is unacceptable. (For example, if your client is running your heart pacemaker, be careful.) If you are renaming or deleting a column used by the application and intend to fix the application to no longer use that column, yes, you need to stop your clients and fix them. If the number or order of columns is changing, this may break your SQL. One way to avoid this is to program defensively. In INSERT sql, list the columns: INSERT INTO foo (bar, baz, name) VALUES (99, 12, 'George'); NOT INSERT INTO foo VALUES (99, 12, 'George'); which will break if someone adds a 4th column. well will it? Does Mysql complain or simply fill the first three? I must say my preference is: INSERT INTO foo set bar='99', baz='12', name='George'); Simply because I find it easier to relate to things as name/value pairs... |
|
Don't use SELECT * FROM ...; . Name the columns. This protects you against problems when adding or re-arranging the order of the columns. Again, if using - say - PHP the data is orgainised in a field name indexed associative array, so it doesn't matter what the order is if you use the indices to access it. |
#20
| |||
| |||
|
|
If the number or order of columns is changing, this may break your SQL. One way to avoid this is to program defensively. In INSERT sql, list the columns: INSERT INTO foo (bar, baz, name) VALUES (99, 12, 'George'); NOT INSERT INTO foo VALUES (99, 12, 'George'); which will break if someone adds a 4th column. well will it? Yes, the error i get is: ERROR 1136 (21S01): Column count doesn't match value count at row 1 |
|
Again, if using - say - PHP the data is orgainised in a field name indexed associative array, so it doesn't matter what the order is if you use the indices to access it. I have found that to be a problem on occasion when the value being selected is an expression (perhaps a messy, complicated one) and trying to figure out what name it has in the associative array isn't always easy. It may also make it much harder to figure out what code actually uses a given field, should you be thinking of changing its type or changing what's in it. |
![]() |
| Thread Tools | |
| Display Modes | |
| |