Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
大型审计表上的mysql索引日期与日期时间_Mysql_Sql_Percona - Fatal编程技术网

大型审计表上的mysql索引日期与日期时间

大型审计表上的mysql索引日期与日期时间,mysql,sql,percona,Mysql,Sql,Percona,我有一个审计表,它目前在innodb上运行大约2500万行,每月增长大约100万行。 我目前在datetime列上有一个索引。 出于性能原因,如果用户搜索,则限制为当天。 如果我将datetime拆分为两个单独的字段,并且在date字段上有一个索引,索引性能会更好吗。 我怀疑这也会创建一个较小的索引,因为您没有索引datetime字段的每一秒。 我还可以从分区这个表中获益 目前正在运行percona 5.5。这取决于查询的措辞。如果查询的措辞为: where date(datetimecol)

我有一个审计表,它目前在innodb上运行大约2500万行,每月增长大约100万行。 我目前在datetime列上有一个索引。 出于性能原因,如果用户搜索,则限制为当天。 如果我将datetime拆分为两个单独的字段,并且在date字段上有一个索引,索引性能会更好吗。 我怀疑这也会创建一个较小的索引,因为您没有索引datetime字段的每一秒。 我还可以从分区这个表中获益


目前正在运行percona 5.5。

这取决于查询的措辞。如果查询的措辞为:

where date(datetimecol) = curdate()
where datecol = curdate()
where datetimecol >= curdate () and
      datetimecol < date_add(curdate(), interval 1 day)
那么这个索引就不会被使用了。如果查询的措辞为:

where date(datetimecol) = curdate()
where datecol = curdate()
where datetimecol >= curdate () and
      datetimecol < date_add(curdate(), interval 1 day)
如果查询的措辞为:

where date(datetimecol) = curdate()
where datecol = curdate()
where datetimecol >= curdate () and
      datetimecol < date_add(curdate(), interval 1 day)
其中datetimecol>=curdate()和
datetimecol

然后将(可能)使用索引

这取决于查询的措辞。如果查询的措辞为:

where date(datetimecol) = curdate()
where datecol = curdate()
where datetimecol >= curdate () and
      datetimecol < date_add(curdate(), interval 1 day)
那么这个索引就不会被使用了。如果查询的措辞为:

where date(datetimecol) = curdate()
where datecol = curdate()
where datetimecol >= curdate () and
      datetimecol < date_add(curdate(), interval 1 day)
如果查询的措辞为:

where date(datetimecol) = curdate()
where datecol = curdate()
where datetimecol >= curdate () and
      datetimecol < date_add(curdate(), interval 1 day)
其中datetimecol>=curdate()和
datetimecol

然后将(可能)使用索引

我不使用第一个示例中显示的函数。我更关心的是在一个日期字段和日期时间字段上执行一个超过6个月的时间框架的性能。这可能是因为B树索引已经针对这种情况进行了优化,所以在速度上不会有真正的差异。@tsmgeek。我不知道你担心什么。如果您要从6个月的时间范围内检索数据,那么获取行的时间可能会主导查询。我们还运行一个限制,以便用户在一个页面上不会收回超过500个审核,但在大型数据集上,初始搜索时间可能需要一段时间。这更多的是关于索引优化,在DATETIME列上索引可能太大,几乎每一行都是唯一的,但是如果我使用DATE,那么它的基数会更好。@tsmgeek。您应该提出另一个问题并显示整个查询。例如,如果您有一个按
排序的
,那么这可能是性能不佳的原因。我不使用第一个示例中显示的函数。我更关心的是在一个日期字段和日期时间字段上执行一个超过6个月的时间框架的性能。这可能是因为B树索引已经针对这种情况进行了优化,所以在速度上不会有真正的差异。@tsmgeek。我不知道你担心什么。如果您要从6个月的时间范围内检索数据,那么获取行的时间可能会主导查询。我们还运行一个限制,以便用户在一个页面上不会收回超过500个审核,但在大型数据集上,初始搜索时间可能需要一段时间。这更多的是关于索引优化,在DATETIME列上索引可能太大,几乎每一行都是唯一的,但是如果我使用DATE,那么它的基数会更好。@tsmgeek。您应该提出另一个问题并显示整个查询。例如,如果您有一个由订购的,那么这可能是性能不佳的原因。