php - MySQL database table design for black lists -


i have php application , need store black list data. site members add user his/her black list. won't see texts of users.

every user's black list different.
user can have 1000-1500 users in his/her black list.
user can add/remove his/her list.
black list have member's id , black listed people's ids.

i'm trying design database table this. couldn't sure how can structure ?
have 7-8 mysql tables none of them this.

way 1:

--member id-----black listed people (blob) ----------------------------------------- --1234----------(some blob data)--------- --6789----------(some blob data)--------- 

i can serialize blacklisted people's ids , save them inside blob data column. when user want edit his/her list, blob data table, remove unwanted id , update column new data. seems bit slow operation when user has 1k-2k ids.

way 2:

--member id----black listed id-------- -------------------------------------- --1234---------113434545-------------- --1234---------444445454-------------- --1234---------676767676-------------- --6789---------534543545-------------- --6789---------353453454-------------- 

in way, when user wants see his/her black list give them users in "black listed id" column. when editing add/remove new rows table. operation fast table can huge in time.

way 3:

--member id----113434545----444445454----676767676---534543545-----353453454 ---------------------------------------------------------------------------- --1234--------yes------------yes------------yes------------no------no------- --6789--------no-------------no-------------no-------------yes------yes------ 

yes shows black listed, no shows not black listed. create new column each black listed person , update column when user adds person or removes it.

way 4:

???

these ideas. appreciate if can offer me better one? thank you.

what creating so-called 1 n relation table.

3rd version

the 3rd version require have n rows x n columns, n amount of registred users. innodb has limit of 1000 columns, breaking logic 1001st. user registers. not mention don´t want alter table every new user. forget that.

1st version

the first solution slow: blob data won´t idexed, tends second page (file on harddisk, doubeling disk i/o), has massive datasize overhead, sorting , grouping won't happen in ram, , have no efficient way backwards search (how many people did blacklist user xy?)... general advise, try avoid blob untill absolutely necesarry.

2nd version

the second solution way go. mysql optimized stuff that, , table 2 numeric, indexed rows really fast.

table design

i create table consisting of blocker_id | blocked_id , no separate primary key. instead create 2-column-primary-key blocker beeing first column , blocked second. way save b-tree (expensive create index) , can search fast both blockeds blocker (using half of key) , existence of single combination. (that relevant filtering posts, , should optimized for.)


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -