Home > Database > Mysql Tutorial > mysql妙用bit存储信息

mysql妙用bit存储信息

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:17:58
Original
1293 people have browsed it

做游戏要存储用户经过城市列表,我想用varchar类型存,大自然提出用比特存信息的好办法,这样一来,我比原来就减少了至少一半的mysql网络请求开销,同时也让mysql的空间节省了许多。 比如,我要标记第三个城市的为已经访问过,我更新bit数据的SQL语句是这样

做游戏要存储用户经过城市列表,我想用varchar类型存,大自然提出用比特存信息的好办法,这样一来,我比原来就减少了至少一半的mysql网络请求开销,同时也让mysql的空间节省了许多。

比如,我要标记第三个城市的为已经访问过,我更新bit数据的SQL语句是这样的(用到了位操作的与、或、移位):

UPDATE `characters` SET `visited_cities` = visited_cities | (1
<p>从cities表找到对应的city:</p>

<pre class="brush:php;toolbar:false">SELECT t1.* from cities as t1, characters as t2 where (1<br>
<span>上面的visited_cities字段是bigint(64位)</span>

<p>真是很方便。</p>
<p><br>
</p>
<p><br>
</p>
<p><br>
</p>


Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template