When you have a TEXT field in MySQL or PostgreSQL, should you put it in a separate table?

后端 未结 3 1486
独厮守ぢ
独厮守ぢ 2021-01-18 12:38

I\'ve heard that if you have a table with a TEXT column that will hold a large chunk of text data, it\'s better for performance to move that column into a separate table and

3条回答
  •  深忆病人
    2021-01-18 13:05

    In some scenarios, this might be true. The reason is that let's say your table is:

    create table foo (
        id serial primary key,
        title varchar(200) not null,
        pub_date datetime not null,
        text_content text
    );
    

    Then you do a query like this:

    select id, title, pub_date
      from foo;
    

    You will have to load much more pages from disk that you would have if you didn't have the text_content field in that table. And query optimization is most about reducing disk I/O to the minimum possible.

提交回复
热议问题