分表分庫的xml書寫(京東的全是單錶操作)

2021-09-24 20:16:16 字數 2597 閱讀 7919

背景介紹:

京東的資料都是分庫分表,所以為了方便全是單錶操作。不存在join使用。每張表必須有表示刪除與否,沒有真正的刪除。但是我也很奇怪,但是業務量太大了,為了方便查詢和維護。所有操作都是單錶。但是在分表業務中,設計同乙個表多個。那麼怎麼打到不同的表上呢:  通過xml中拼接,例項如下

<?xml version="1.0" encoding="utf-8" ?>

skuid, jd_shopid,jd_dealerid,shop_groupid,

productid,status ,

create_time,update_time,creator,updator,is_valid

skuid = #skuid#

jd_shopid = #jd_shopid#

jd_dealerid = #jd_dealerid#

shop_groupid = #shop_groupid#

productid = #productid#

status = #status#

is_valid = #is_valid#

insert into()

values(

#skuid#, #jd_shopid#,#jd_dealerid#,#shop_groupid#,

#productid#,#status# ,

now(),now(),#creator#,#updator#,1

)update

setis_valid = 0 ,

update_time = now()

where id=#id#

select

from

where 1 = 1

$ordertype$

order by id desc

limit #startrow#,#endrow#

select count(0) c

from

where 1 = 1

update

is_valid=#is_valid#

status=#status#

updator=#updator#

update_time=#update_time#

where jd_shopid=#jd_shopid#

skuid=#skuid#

/*and status !=-1*/

update

is_valid=#is_valid#

status=#status#

updator=#updator#

update_time=#update_time#

where jd_shopid=#jd_shopid# /*and status !=-1*/

select

from

where skuid=#skuid# and jd_shopid =#jd_shopid#

delete from

select count(id) from

select s_sku.skuid as wareid,s_sku.name as warename,price as dredisprice,commentcount as commentcount,goodrate as good,

master_img as imageurl,s_sku.item_model as itemmodel,shop_sku.jd_shopid as shop_id,s_shop.name as shopname,s_sku.jd_dealerid as dealerid,

s_dealer.alias as shopbrank,s_shop.maps as maps,s_shop.province_code as provincecode,s_shop.province_name as provincename,s_shop.city_code as citycode,

s_shop.city_name as cityname,s_shop.area_code as areacode,s_shop.area_name as areaname ,s_shop.address

,item_type as itemtype,s_sku.is_recommend as recommend, s_sku.cat_type as cattype, s_sku.jd_catid as cattype2

from

as shop_sku

join s_sku on s_sku.skuid=shop_sku.skuid

join s_shop on shop_sku.jd_shopid=s_shop.jd_shopid

join s_dealer on s_sku.jd_dealerid=s_dealer.jd_dealerid

where s_sku.status =1 and s_sku.is_valid=1 and s_sku.price>0 and shop_sku.status=1 and s_dealer.is_valid=1 and s_shop.is_valid=1 and s_sku.item_model=0

limit #pagestart#,#pagelimit#

推薦乙個部落格很好:  分表分庫解析加案例

分庫分表的排序

author skate time 2013 05 20 分庫分表的排序 1.對於單庫,冗餘乙個彙總所有資料表,用於全部資料的排序,但是當資料量大,彙總表將會成為瓶頸。這不是乙個很好的方案 2.無論單庫還是多個分庫,都由程式讀取需要資料並作排序。排序的幾種方式 大都是按時間排序的,如果在客戶端可以直...

分庫分表的依據

1 磁碟io瓶頸 分庫和垂直分表 2 網路io瓶頸,請求的資料太多,網路頻寬不夠 分庫 1 sql問題,如sql中包含join,group by,order by,非索引字段條件查詢等,增加cpu運算的操作 sql優化,建立合適的索引,在業務service層進行業務計算 2 單錶資料量太大,查詢時掃...

分庫分表的排序

分庫分表的排序 分庫分表的排序 1.對於單庫,冗餘乙個彙總所有資料表,用於全部資料的排序,但是當資料量大,彙總表將會成為瓶頸。這不是乙個很好的方案 2.無論單庫還是多個分庫,都由程式讀取需要資料並作排序。排序的幾種方式 大都是按時間排序的,如果在客戶端可以直接判斷在哪個分表最好,可以直接讀取指定分表...