【问题标题】:MySQL server overload with large text query?MySQL 服务器因大文本查询而过载?
【发布时间】:2011-12-27 17:02:43
【问题描述】:

我使用这样的东西:

    $url_title = mysql_real_escape_string($_GET['title']); 
    $sql = dbquery("SELECT * FROM `videos` WHERE `post_name` = '$url_title' LIMIT 0, 1");

/* or this old one

    $local_id = ($_GET['id'];
    $sql = dbquery("SELECT * FROM `videos` WHERE `id` = '$local_id' LIMIT 0, 1");

// for urls like : 
// example.com/video/music/red-hot-chili-peppers-californication-564/

*/

    $num_rows = mysql_num_rows($sql);
    if  ($num_rows == "0"){die();}
    
    while($row = mysql_fetch_array($sql)){
    $local_id = $row["id"]; // PRIMARY KEY ; auto increment
    $video_id = $row["youtube_id"]; // Unique
    $title = $row["name"]; // Unique
    $name_slug = $row["name_slug"]; // Unique
    // some more code
    }

// and this one for urls like : 
// example.com/video/music/red-hot-chili-peppers-californication/

我想问的是:

当我在数据库中查询“red-hot-chili-peppers-californication”而不是“564”时,服务器负载是否正常?

所有字段的类型都是varchar,除了$id是int。

【问题讨论】:

  • 你的桌子上有什么索引?
  • 但是表上有什么索引呢?如果标题列上没有索引,它会明显变慢
  • 我没有。据我所知,我认为我应该对我查询的字段使用索引。如果我想使用第二个 url 结构,我认为向 $name_slug 添加索引是正常的。那正确吗?我可以为该字段同时使用索引和唯一性吗?
  • 是的,听起来你想要一个关于名称 slug 的唯一索引
  • 谢谢你的回答,但是 mysql 的命令是什么?

标签: php mysql load


【解决方案1】:

我认为这是正常的。比较数字比比较字符串更容易。在每种编程语言中。

【讨论】:

  • 那是你必须测试的东西。这取决于您的硬件、表引擎、表的大小等。
【解决方案2】:

一切都取决于你如何为 mysql 列设置type

【讨论】:

  • 类型是 varchar 如果这是你问我的,我应该用别的吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多