MySQL查询性能 [英] MySQL query performance

查看:159
本文介绍了MySQL查询性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下表格结构:

EVENT_ID(INT)    EVENT_NAME(VARCHAR)    EVENT_DATE(DATETIME)    EVENT_OWNER(INT)

我需要添加字段EVENT_COMMENTS,该字段应该是文本字段或很大的VARCHAR.

I need to add the field EVENT_COMMENTS which should be a text field or a very big VARCHAR.

我在2个地方查询此表,其中一个位于列出所有事件的页面上(在该页面中,我不需要显示event_comments字段).

I have 2 places where I query this table, one is on a page that lists all the events (in that page I do not need to display the event_comments field).

另一个页面将加载特定事件的所有详细信息,我将需要在该页面上显示event_comments字段.

And another page that loads all the details for a specific events, which I will need to display the event_comments field on.

我是否应该使用该事件的event_id和event_comments创建一个额外的表?还是我应该在当前表格中添加该字段?

Should I create an extra table with the event_id and the event_comments for that event? Or should I just add that field on the current table?

换句话说,我要问的是,如果我的表中有一个文本字段,但是我没有SELECT,它会影响对我的表的查询性能吗?/strong>

In other words, what I'm asking is, if I have a text field in my table, but I don't SELECT it, will it affect the performance of the queries to my table?

推荐答案

向表中添加字段会使字段变大.

Adding a field to your table makes it larger.

这意味着:

  • 表扫描将花费更多时间
  • 较少的记录将适合页面,因此适合高速缓存,因此增加了高速缓存未命中的风险

但是,通过联接选择此字段将花费更多时间.

Selecting this field with a join, however, would take more time.

因此,将此字段添加到此表中会使未选择该字段的查询运行速度较慢,而选择该字段的查询运行速度更快.

So adding this field into this table will make the queries which don't select it run slower, and those which do select it run faster.

这篇关于MySQL查询性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆