请问大家如何根据下面的PHP代码建立最佳索引呢?
时间:2011-09-02
来源:互联网
<?php
//用户名称
$userName= isset($_GET['userName']) ? trim($_GET['userName']) : NULL;
//起始时间
$dateStart= isset($_GET['dateStart']) ? strtotime(trim($_GET['dateStart'])) : NULL;
//终止时间
$dateEnd= !empty($_GET['dateEnd']) ? strtotime(trim($_GET['dateEnd']).' 23:59:59') : NULL;
if(empty($userName)){
die('请输入用户名');
}
if(!empty($userName)){
$where .= ' where `user_name`="'.$userName.'"';
}
if(!empty($dateStart)){
$where .= ' and `start_time`>'.$dateStart;
}
if(!empty($dateEnd)){
$where .= ' and `end_time`<'.$dateEnd;
}
?>
对于上面的代码,我的困惑在于,用户名,起始时间和终止时间都可能有输入,但是不知道如果最好地建立索引。请问大家如何根据上面的PHP代码,为Mysql表中的 user_name,start_time,end_time建立组合索引呢?谢谢!
//用户名称
$userName= isset($_GET['userName']) ? trim($_GET['userName']) : NULL;
//起始时间
$dateStart= isset($_GET['dateStart']) ? strtotime(trim($_GET['dateStart'])) : NULL;
//终止时间
$dateEnd= !empty($_GET['dateEnd']) ? strtotime(trim($_GET['dateEnd']).' 23:59:59') : NULL;
if(empty($userName)){
die('请输入用户名');
}
if(!empty($userName)){
$where .= ' where `user_name`="'.$userName.'"';
}
if(!empty($dateStart)){
$where .= ' and `start_time`>'.$dateStart;
}
if(!empty($dateEnd)){
$where .= ' and `end_time`<'.$dateEnd;
}
?>
对于上面的代码,我的困惑在于,用户名,起始时间和终止时间都可能有输入,但是不知道如果最好地建立索引。请问大家如何根据上面的PHP代码,为Mysql表中的 user_name,start_time,end_time建立组合索引呢?谢谢!
作者: moumouguo 发布时间: 2011-09-02
代码很有趣, 你的$userName显然是必填项。 就不用再if(!empty($userName)){ $where .= ' where `user_name`="'.$userName.'"';}
create index idx01 on xxxtable(user_name,start_time);
create index idx02 on xxxtable(user_name,end_time);
另外建议在MYSQL版中尽量直接贴你的SQL语句,不要再让别人来分析你的PHP代码。并不是每个MYSQL使用者都需要去懂PHP的。
问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
create index idx01 on xxxtable(user_name,start_time);
create index idx02 on xxxtable(user_name,end_time);
另外建议在MYSQL版中尽量直接贴你的SQL语句,不要再让别人来分析你的PHP代码。并不是每个MYSQL使用者都需要去懂PHP的。
问题说明越详细,回答也会越准确!参见如何提问。(提问的智慧)
作者: ACMAIN_CHM 发布时间: 2011-09-02
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28