久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

如何使用MySQL位圖索引解決用戶畫像問題

共計(jì) 4573 個(gè)字符,預(yù)計(jì)需要花費(fèi) 12 分鐘才能閱讀完成。

這篇文章給大家分享的是有關(guān)如何使用 MySQL 位圖索引解決用戶畫像問題的內(nèi)容。丸趣 TV 小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨丸趣 TV 小編過來看看吧。

每個(gè) bigint 類型包括 60 個(gè)記錄的位信息.

但是第 0 位表示第六十個(gè)記錄的位

第 1 位至第 59 位表示第一至五十九的記錄的位信息.

這樣記錄的位信息保存并不連續(xù),

使用的時(shí)候還得把最右邊的一位挪到最左邊, 不好理解還非常麻煩, 性能也有損耗.

經(jīng)過王工的改良,

使用如下 sql 替換,則保存的位信息就連續(xù)了

SELECT 
 CEIL(id / 60) g60,
 CEIL(id / 1200) g1200,
 age grouped,
 COUNT(*) total,
 BIT_OR(1   (if(MOD(id, 60)=0,60,MOD(id, 60)))) bitmap
 FROM
 o_huaxiang_big_0 o
 GROUP BY g1200 , g60 , age

創(chuàng)建位圖索引的整體 SQL 如下

truncate table bitmap20_0;
insert into bitmap20_0 
select 
  o_huaxiang_big  table_name,
  umc_sex  column_name,
 ((g1200-1)*60)*20 min_id,
 ((g1200-1)*60)*20+1200 max_id,
 v2.*
from (
 select 
 g1200,
 grouped,
 sum(total) total, 
 ifnull(max(case when abs((g1200-1)*20-g60)=20 then bitmap else null end),0) c20,
 ifnull(max(case when abs((g1200-1)*20-g60)=19 then bitmap else null end),0) c19,
 ifnull(max(case when abs((g1200-1)*20-g60)=18 then bitmap else null end),0) c18,
 ifnull(max(case when abs((g1200-1)*20-g60)=17 then bitmap else null end),0) c17,
 ifnull(max(case when abs((g1200-1)*20-g60)=16 then bitmap else null end),0) c16,
 ifnull(max(case when abs((g1200-1)*20-g60)=15 then bitmap else null end),0) c15,
 ifnull(max(case when abs((g1200-1)*20-g60)=14 then bitmap else null end),0) c14,
 ifnull(max(case when abs((g1200-1)*20-g60)=13 then bitmap else null end),0) c13,
 ifnull(max(case when abs((g1200-1)*20-g60)=12 then bitmap else null end),0) c12,
 ifnull(max(case when abs((g1200-1)*20-g60)=11 then bitmap else null end),0) c11,
 ifnull(max(case when abs((g1200-1)*20-g60)=10 then bitmap else null end),0) c10,
 ifnull(max(case when abs((g1200-1)*20-g60)=9 then bitmap else null end),0) c9,
 ifnull(max(case when abs((g1200-1)*20-g60)=8 then bitmap else null end),0) c8,
 ifnull(max(case when abs((g1200-1)*20-g60)=7 then bitmap else null end),0) c7,
 ifnull(max(case when abs((g1200-1)*20-g60)=6 then bitmap else null end),0) c6,
 ifnull(max(case when abs((g1200-1)*20-g60)=5 then bitmap else null end),0) c5,
 ifnull(max(case when abs((g1200-1)*20-g60)=4 then bitmap else null end),0) c4,
 ifnull(max(case when abs((g1200-1)*20-g60)=3 then bitmap else null end),0) c3,
 ifnull(max(case when abs((g1200-1)*20-g60)=2 then bitmap else null end),0) c2,
 ifnull(max(case when abs((g1200-1)*20-g60)=1 then bitmap else null end),0) c1
 from (
 SELECT 
 CEIL(id / 60) g60,
 CEIL(id / 1200) g1200,
 umc_sex grouped,
 COUNT(*) total,
 BIT_OR(1   (if(MOD(id, 60)=0,60,MOD(id, 60)))) bitmap
 FROM
 o_huaxiang_big_0 o
 GROUP BY g1200 , g60 , umc_sex
 ) v1 group by g1200,grouped
) v2;
 
insert into bitmap20_0 
select 
  o_huaxiang_big  table_name,
  age  column_name,
 ((g1200-1)*60)*20 min_id,
 ((g1200-1)*60)*20+1200 max_id,
 v2.*
from (
 select 
 g1200,
 grouped,
 sum(total) total, 
 ifnull(max(case when abs((g1200-1)*20-g60)=20 then bitmap else null end),0) c20,
 ifnull(max(case when abs((g1200-1)*20-g60)=19 then bitmap else null end),0) c19,
 ifnull(max(case when abs((g1200-1)*20-g60)=18 then bitmap else null end),0) c18,
 ifnull(max(case when abs((g1200-1)*20-g60)=17 then bitmap else null end),0) c17,
 ifnull(max(case when abs((g1200-1)*20-g60)=16 then bitmap else null end),0) c16,
 ifnull(max(case when abs((g1200-1)*20-g60)=15 then bitmap else null end),0) c15,
 ifnull(max(case when abs((g1200-1)*20-g60)=14 then bitmap else null end),0) c14,
 ifnull(max(case when abs((g1200-1)*20-g60)=13 then bitmap else null end),0) c13,
 ifnull(max(case when abs((g1200-1)*20-g60)=12 then bitmap else null end),0) c12,
 ifnull(max(case when abs((g1200-1)*20-g60)=11 then bitmap else null end),0) c11,
 ifnull(max(case when abs((g1200-1)*20-g60)=10 then bitmap else null end),0) c10,
 ifnull(max(case when abs((g1200-1)*20-g60)=9 then bitmap else null end),0) c9,
 ifnull(max(case when abs((g1200-1)*20-g60)=8 then bitmap else null end),0) c8,
 ifnull(max(case when abs((g1200-1)*20-g60)=7 then bitmap else null end),0) c7,
 ifnull(max(case when abs((g1200-1)*20-g60)=6 then bitmap else null end),0) c6,
 ifnull(max(case when abs((g1200-1)*20-g60)=5 then bitmap else null end),0) c5,
 ifnull(max(case when abs((g1200-1)*20-g60)=4 then bitmap else null end),0) c4,
 ifnull(max(case when abs((g1200-1)*20-g60)=3 then bitmap else null end),0) c3,
 ifnull(max(case when abs((g1200-1)*20-g60)=2 then bitmap else null end),0) c2,
 ifnull(max(case when abs((g1200-1)*20-g60)=1 then bitmap else null end),0) c1
 from (SELECT 
 CEIL(id / 60) g60,
 CEIL(id / 1200) g1200,
 age grouped,
 COUNT(*) total,
 BIT_OR(1   (if(MOD(id, 60)=0,60,MOD(id, 60)))) bitmap
 FROM
 o_huaxiang_big_0 o
 GROUP BY g1200 , g60 , age
 ) v1 group by g1200,grouped
) v2;

感謝各位的閱讀!關(guān)于“如何使用 MySQL 位圖索引解決用戶畫像問題”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-07-26發(fā)表,共計(jì)4573字。
轉(zhuǎn)載說明:除特殊說明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請(qǐng)注明出處。
評(píng)論(沒有評(píng)論)
主站蜘蛛池模板: 辉县市| 新宾| 诸暨市| 伊吾县| 普兰店市| 曲松县| 那坡县| 宿迁市| 武川县| 寿光市| 德江县| 扶绥县| 奈曼旗| 万荣县| 屯昌县| 芦山县| 广汉市| 盘锦市| 二连浩特市| 咸宁市| 韶关市| 读书| 祁连县| 密云县| 柳林县| 柘荣县| 台南县| 红河县| 合川市| 田阳县| 芷江| 山东省| 离岛区| 玉林市| 侯马市| 玛纳斯县| 鱼台县| 将乐县| 淮滨县| 广丰县| 湖北省|