【问题标题】:quering mysql with and without index returns totally different results使用和不使用索引查询 mysql 返回完全不同的结果
【发布时间】:2014-01-21 12:14:06
【问题描述】:

我有一张表格来保存我的付款记录。并且它有订阅者 id 字段...所以当我在没有索引的情况下查询此字段时,它会返回 4 个值,如下所示...

select count(id) from `mydb`.`sale_transaction` where subscriber_guid='4d03a32c-3dca-472b-a1db-0dfb0f66e64d';
+-----------+
| count(id) |
+-----------+
|         4 |
+-----------+
1 row in set (0.31 sec)

所以我想通过这个字段更快地获取数据,我添加了一个这样的索引......

alter table sale_transaction add index subscriber_guid_index(subscriber_guid);
Query OK, 0 rows affected (1.00 sec)
Records: 0  Duplicates: 0  Warnings: 0

然后再次进行相同的查询...

select count(id) from `mydb`.`sale_transaction` where subscriber_guid='4d03a32c-3dca-472b-a1db-0dfb0f66e64d';
+-----------+
| count(id) |
+-----------+
|         0 |
+-----------+
1 row in set (0.00 sec)

如果我删除索引,它会再次起作用...

alter table sale_transaction drop index subscriber_guid_index;
Query OK, 0 rows affected (0.06 sec)
Records: 0  Duplicates: 0  Warnings: 0

select count(id) from `mydb`.`sale_transaction` where subscriber_guid='4d03a32c-3dca-472b-a1db-0dfb0f66e64d';
+-----------+
| count(id) |
+-----------+
|         4 |
+-----------+
1 row in set (0.29 sec)

以前没有见过这样的东西,我的错误是什么?

【问题讨论】:

    标签: python mysql indexing alter-table


    【解决方案1】:

    问题解决了

    OPTIMIZE TABLE sale_transaction;
    

    现在我可以根据subscriber_guid 进行查询了。

    【讨论】:

      【解决方案2】:

      我认为问题是因为:

      ft_min_word_len 变量设置不准确。

      参考:

      http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_ft_min_word_len

      【讨论】:

      • ft_min_word_len 仅用于FULLTEXT 列,但我们不知道subscriber_guid_index 是什么类型。
      • 它是 char(36),但我也没有制作全文索引。
      猜你喜欢
      • 2021-11-27
      • 2020-02-15
      • 2013-07-05
      • 1970-01-01
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      相关资源
      最近更新 更多