search

Home  >  Q&A  >  body text

mysql optimization gender optimization

There are hundreds of thousands of users in the database, 90% of whom are men, sex = 1
For example: select uid member where sex =1 and xxx xx
Then this sex will scan the entire table, how to deal with it

怪我咯怪我咯2747 days ago746

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-05-18 10:53:08

    In this case, the discrimination of indexing on sex is too low, and it is of little use. Let’s consider creating indexes on other fields, such as the xxx below

    reply
    0
  • ringa_lee

    ringa_lee2017-05-18 10:53:08

    Creating a single-column index on sex can avoid full table scanning. If the efficiency is not high, you can consider establishing a joint index starting with sex and adding subsequent fields

    reply
    0
  • 阿神

    阿神2017-05-18 10:53:08

    Put sex in the first place in the multi-column index and process it programmatically. For example, when all of them are sex in (1, 2)

    reply
    0
  • Cancelreply