[development] schema API add column after

Khalid Baheyeldin kb at 2bits.com
Tue Jun 10 04:18:08 UTC 2008


On Mon, Jun 9, 2008 at 4:43 PM, Karoly Negyesi <karoly at negyesi.net> wrote:

> > Make sense?
>
> Nope. I try to refrain from being a maths egghead but SQL does not need or
> rely on column order.
>

Agreed.

If you are saying:

INSERT INTO tablename VALUES ('a', 1, 2, 3, 'b');

Instead of

INSERT INTO tablename (col1, col4, col2, col5, col3) VALUES ('a', 1, 2, 3,
'b');

Then you should change the former to the latter for maintenance's sake.

(If you are coding for Drupal 6, better use drupal_write_record() anyways).

But, there is a good reason to be able to control the column order:
performance.

If you have numeric or short columns following varchar or text columns,
MySQL has to work more if you do a WHERE on the short columns vs. if the
shorter and numeric columns are before the text columns.

So, yes, don't rely on column positions from the programming point of view,
but from a DBA point of you, they can make a difference. In fact NOT relying
on the order when coding makes the life of a DBA easier, since he can move
columns around as needed, without breaking code, whereas it would be
impossible to do so if the code relies on position.
-- 
Khalid M. Baheyeldin
2bits.com, Inc.
http://2bits.com
Drupal optimization, development, customization and consulting.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080610/657f1829/attachment.htm 


More information about the development mailing list