What is Faster on a JOIN VARCHAR or INT? (Mysql)

Discussion in 'MySQL' started by jakomo, Mar 26, 2008.

  1. #1
    Hello friends,

    I'd like to know if someone can help me..

    Ie:
    Case A
    - Table with 1000000 fields.
    - Id_company INT(5)
    - Index Id

    SELECT * FROM TABLE WHERE id_company = 1

    Case B
    - Table with 1000000 fields.
    - company varchar(100)
    - Index company

    SELECT * FROM TABLE WHERE company = 'company_name'

    What is faster A or B ? Is better use INT than varchar?

    Best regards and thanks for your time,
    Jakomo
     
    jakomo, Mar 26, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Int(5) would most likely be faster than varchar(100).

    Make sure you have an index on the column in the where clause in either case.

    You can also test yourself by making a simple test script. Get the time before the query starts and the time after and calculate the difference between them.

    Also, if you don't need negative numbers an unsigned smallint(5) should be faster than int.
     
    jestep, Mar 26, 2008 IP
  3. Mr_2

    Mr_2 Peon

    Messages:
    980
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    usualy prevent using "*" better using the column names instead.
     
    Mr_2, Mar 27, 2008 IP
  4. silvalex

    silvalex Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    use (int) and list column names out if you dont truly need all of them. Your question asks about a join, but I dont see one in your query.
     
    silvalex, Mar 27, 2008 IP