Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:12:14+00:00 2026-05-25T19:12:14+00:00

For example if I have a table User, I want to store gender or

  • 0

For example if I have a table User, I want to store gender or sex, I’ll add a column like sex.

Is it really worth to use an integer and then map it in my favorite programming language?

Like 1 => 'Male' and 2 => 'Female'

Is there any performance reason to do that?

Or could I safely use a varchar which more meaning with ‘female’ or ‘male’ almost like I was using mysql ENUM ?

Edit: I here and there that it is sometimes better, sometimes it doesn’t matter, so I more looking for benchmark or something over a “it is better” answer.

I mean I think using varchar is actually more meaningfull than an integer, and I would use an integer only if performance are more than 0.3% or something.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:12:14+00:00Added an answer on May 25, 2026 at 7:12 pm

    Ortiginal Answer:
    I would suggest storing it in a CHAR(1) column as M or F
    It is expressive enough for the specific purpose AND has the speed benefit of being a single character comparison

    Update 4 (fixed benchmark):
    All previous benchmarks had a fatal flaw that one (the CHAR(1)) table was MyISAM and all other were InnoDB. So I recreated the database with all tables using the MyISAM and the results make much more sense now.

    The error creeped in as I used the MySQLWorkbench’s wizard to create the tables and forgot to change the database engine in the other tables and it defaulted to InnoDB (I have MySQL 5.5)

    So the corrected results are as follows, (I have removed all my previous benchmarks as they were invalid) :

    // select queries
    $query['char'] = "select count(*) from test_table where gender = 'M'";
    $query['char_lower'] = "select count(*) from test_table where LOWER(gender) = 'm'";
    $query['varchar'] = "select count(*) from test_table_2 where gender = 'Male'";
    $query['varchar_lower'] = "select count(*) from test_table_2 where LOWER(gender) = 'male'";
    $query['tinyint'] = "select count(*) from test_table_3 where gender = 1";
    
    // benchmark result
    array
      'char' => float 0.35457420349121
      'char_lower' => float 0.44702696800232
      'varchar' => float 0.50844311714172
      'varchar_lower' => float 0.64412498474121
      'tinyint' => float 0.26296806335449
    

    New Conclusion : TINYINT Is fastest. But my recommendation would be still yo use CHAR(1) as it would be easier for future developers to understand the database.

    If you do use TINYINT, my recommendation would be name the column ismale instead of sex and store 0 => Female and 1 => male thus making it a little more easy to understand in raw database.

    The table structure for benchmark is this:

    CREATE TABLE `test_table` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `gender` char(1) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM
    

    Only the type of the gender column is different in the 3 tables, the types are:

    CHAR(1), VARCHAR(6), TINYINT
    

    All 3 tables have 10000 entries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table similar to this: CREATE TABLE example ( id integer primary
I have a Car table and User table which store car and user particular.
For example I have a table. With a field Idnumber. And the field has
I have a question about Access.If for example I have a table with the
I have a table, for example, mytable. It has several columns: col1, col2, col3.
I have a table which defines what things another table can have, for example:
I have a table, has many rows. for example one of from rows(all rows
I have a table, has many rows. for example one of from rows(all rows
It's common to have a table where for example the the fields are account,
For example, I have a table TableA, with columns Field1, Field2 and Field3. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.