Mysql uses bit to store information

Source: Internet
Author: User
When playing games, you need to store the user list through the city list. I want to use the varchar type for storage, and nature proposes a good way to store information with bits. In this way, I have reduced the mysql network request overhead by at least half, and saved a lot of space for mysql. For example, if I want to mark a third city as already accessed, the SQL statement for updating bit data is as follows:

When playing games, you need to store the user list through the city list. I want to use the varchar type for storage, and nature proposes a good way to store information with bits. In this way, I have reduced the mysql network request overhead by at least half, and saved a lot of space for mysql. For example, if I want to mark a third city as already accessed, the SQL statement for updating bit data is as follows:

When playing games, you need to store the user list through the city list. I want to use the varchar type for storage, and nature proposes a good way to store information with bits. In this way, I have reduced the mysql network request overhead by at least half, and saved a lot of space for mysql.

For example, if I want to mark a third city as already accessed, the SQL statement for updating bit data is as follows (with the bitwise operation and, Or, shift ):

UPDATE 'characters 'set' visited _ cities '= visited_cities | (1 <2) WHERE 'characters '. 'id' = 1 AND (visited_cities & (1 <2) = 0;

Find the city from the cities table:

SELECT t1. * from cities as t1, characters as t2 where (1 <(t1.id-1) & t2.visited _ cities! = 0

The visited_cities field above is bigint (64-bit)

It's really convenient.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.