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.