Any disadvantages to bit flags in database columns?

前端 未结 4 885
野趣味
野趣味 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条回答
  •  猫巷女王i
    2020-12-30 07:57

    Disadvantages: Hard to write data, hard to read data, hard to debug, but especially: slow queries because the database cannot use indexes on a query like this.

    Advantages, you save a few bytes. Compared to a BIT field, you may save a few MB on a million records table.. hardly worth it. :)

提交回复
热议问题