mysql - 不使用索引的简单 MySQL WHERE 查询

标签 mysql indexing

<小时/>

快速回答:查询条件需要与使用索引的列类型相同。我试图用数字条件搜索 CHAR 列。

<小时/>

我有一个包含 1500 万行的表。我有一个名为“ticket”的列,它可以出现多次,但不会出现很多次。 。 。可能小于 10。我已经在此列上创建了一个索引,但解释命令说,当我使用简单的“WHERE Ticket =”查询时,它没有使用索引。显然,这让我很困惑,因为我在这里问一个问题。

CREATE TABLE company1.rTable (
  `aDate` date DEFAULT NULL,
  `fromD` date DEFAULT NULL,
  `pNo` int(10) DEFAULT NULL,
  `ticket` char(11) DEFAULT NULL,
  `r` int(11) unsigned NOT NULL DEFAULT '0',
  `line` tinyint(3) unsigned DEFAULT NULL,
  `nNum` char(11) NOT NULL,
  `pKey` char(7) DEFAULT NULL,
  `modNum` char(4) DEFAULT NULL,
  `dnum` smallint(5) unsigned NOT NULL,
  `rdNum` smallint(5) unsigned DEFAULT NULL,
  `pType` int(10) DEFAULT NULL,
  `lNum` decimal(9,2) DEFAULT NULL,
  `lineAmount` decimal(9,2) DEFAULT NULL,
  `amount` decimal(9,2) DEFAULT NULL,
  `amount1` decimal(9,2) DEFAULT NULL,
  `amount2` decimal(9,2) DEFAULT NULL,
  `amount3` decimal(9,2) DEFAULT NULL,
  `amount4` decimal(9,2) DEFAULT NULL,
  `amount5` decimal(9,2) DEFAULT NULL,
  `amount6` decimal(9,2) DEFAULT NULL,
  `amount7` decimal(9,2) DEFAULT NULL,
  `amount8` decimal(9,2) DEFAULT NULL,
  `amount9` decimal(9,2) DEFAULT NULL,
  `amount10` decimal(9,2) DEFAULT NULL,
  `tType` tinyint(4) DEFAULT NULL,
  `lineB` decimal(9,2) DEFAULT NULL,
  `lineD` char(1) DEFAULT NULL,
  `lineP` decimal(9,2) DEFAULT NULL,
  `lineI` decimal(9,2) DEFAULT NULL,
  `lineC` decimal(9,2) DEFAULT NULL,
  `lineW` decimal(9,2) DEFAULT NULL,
  `lineR` decimal(9,2) DEFAULT NULL,
  `lineM` decimal(9,2) DEFAULT NULL,
  KEY `rADate` (`aDate`),
  KEY `rTType` (`tType`),
  KEY `rTicket` (`ticket`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1$$

我的查询:

SELECT *
FROM   company1.rTable
WHERE  ticket = 3478421;

也许有办法更改查询以使用索引?我尝试过诸如 'AND Ticket > 之类的事情。 。 .'作为猜测,但这没有帮助。

最佳答案

ticket 是一个字符列,您使用的是数字条件 (3478421)。

关于mysql - 不使用索引的简单 MySQL WHERE 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16550884/

相关文章:

c# - DataTable.Columns.Clear 和列排序后的 DataAdapter.Fill NullReferenceException

mysql - 在 maria db(mysql) 中按顺序和分组进行选择

PHP 循环遍历 2 个基于位置 ID 和日期的表

python - 如何访问 pandas 中嵌套 iterrow 的外部 for 循环的索引?

sql-server - 在 Multi-Tenancy 数据库中索引租户 ID

python - 使用列(键)中的信息更改 Pandas 中的索引名称

mongodb - 复合索引的顺序在 MongoDB 性能方面有何影响?

php - 使用 PHP PDO 处理来自 MySQL SP 的输出参数

mysql 在排序时将包含字母的字段视为最低值

python - 如何在使用 pandas DataFrame.explode() 后创建一个新的 'index' 列?