Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

mysql adapter with mediumt support

#432

First of all: this is my first time ever contributing to an open source project, so please let me know if I've done something wrong.

As of rails 2.1 the mysql adapter of activerecord, is able to use more appropriate data types for integers instead of just the standard INT data type in mysql. However, the MEDIUMINT data type seem to have been left out for some reason. Integer with a length of 5 or 6 should be stored as an mediumt in order to obtain optimal performance from mysql. With this patch, mediumint is now supported.

Also, the lengths have been corrected so that they know fit more appropriately. For instance SMALLINT is now used for integers with length 0-4 instead of 0-3.

I hope this patch is useful. If not, excuse me for my newbie-ism.

-Ras

Reported by Rasmus · June 16th, 2008 @ 09:38 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Rasmus
    Rasmus
    • No changes were found…

    June 18th, 2008 @ 07:20 PM

  2. Pratik
    Pratik
    • State changed from new to invalid
    • Tag set to 2.1, activerecord, enhancement, mysql, patch

    Is this still an issue with Edge rails ? I see mysql_adapter already seems to be having support for medium int.

    Thanks.

    July 9th, 2008 @ 01:18 PM

  3. Rasmus
    Rasmus

    Thank you for your reply.

    Jeremy Kemper added mediumint here:

    http://github.com/rails/rails/co...

    However, I'm personally not sure he has done everything correct.

    Example (taken from jeremy's commit):

    when 1; 'tinyint'

    when 2; 'smallint'

    when 3; 'mediumint'

    For instance, doesn't this mean that rails will choose mediumint as data type for storing integers with a length of 3? That should be smallint! Smallint holds (if signed) -32768 to 32767 so it would easy hold an integer with length of 3 and even 4. Using mediumint here just wastes disk space and increase mysql memory consumption without any reason.

    As I understand rails and mysql data types, it should rather be something like:

    when 0..2; 'tinyint'

    when 2..4; 'smallint'

    when 5..6; 'mediumint'

    when 7..9; 'int'

    when 9..20; 'bigint'

    Or am I missing something here?

    July 9th, 2008 @ 01:32 PM

  4. Pratik
    Pratik
    • Assigned user set to Jeremy Kemper

    I'm not sure to be honest. But you should probably send an email to rails core mailing list - http://groups.google.com/group/r...

    Thanks.

    July 9th, 2008 @ 02:02 PM