Any disadvantages to bit flags in database columns?

前端 未结 4 886
野趣味
野趣味 2020-12-30 07:27

Consider the following tables:

CREATE TABLE user_roles(
    pkey         SERIAL PRIMARY KEY,
    bit_id       BIGINT NOT NULL,
    name         VARCHAR(256)         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 07:56

    There is at least one huge disadvantage here...

    These conditions are non-SARGable!

    This is a big one and for me would be a dealbreaker. The bitwise evaluations you need to perform are (to my knowledge) not indexable in any database - the engine needs to check every row to perform the evaluation, which means terrible performance.

提交回复
热议问题