gpt4 book ai didi

mysql - 带有MYISAM表引擎的MYSQL应该使用什么样的索引

转载 作者:行者123 更新时间:2023-11-29 11:41:15 25 4
gpt4 key购买 nike

下面的查询应该使用哪种索引?请注意,我正在使用 MySQL 和 MYISAM 存储引擎,表包含超过 6M 行,我需要更快地获得结果。我已准备好为此进行内存权衡,谢谢

    SELECT 
`track-item-number` AS awb,
GROUP_CONCAT(DISTINCT(`last-known-location-cd`) ORDER BY last_update SEPARATOR '> ') as PATH,
`pickup-route-number` AS pickupRoute,
`service-type` AS service,
`ursa-code` AS ursa,
GROUP_CONCAT(DISTINCT(`shipper-reference-notes`) SEPARATOR '|') as REF,
MIN(`ship-date`) AS shipDate,
GROUP_CONCAT(DISTINCT(`delivery-date-time`) SEPARATOR '|') as deliveryDateTime,
GROUP_CONCAT(DISTINCT(`received-by-name`) SEPARATOR '|') as receivedBy,
`shipper-account-number` AS shipperAccount,
`bill-to-account-number` AS billtoAccount,
`weight-uom` AS weightType,
`shipment-weight` AS weight,
`shipment-weight-uom` AS shipWeightType,
`dim-source` AS dimSource,
`package-weight-source` AS pkgWeightSource,
`svc-commit-date` AS serviceCommitDate,
`svc-commit-time` AS serviceCommiteTime,
`pkg-length` AS pkgLength,
`pkg-width` AS pkgWidth,
`pkg-height` AS pkgHeight,
`tracking-item-form-cd` AS trackingItemCode,
`dim-volume` AS dimVolume,
`doc-nondoc-flag` AS docFlag,
`service-area` AS serviceArea,
`tracking-item-unique-id` AS trackingUniqueId,
`packaging-type` AS pkgType,
`ese-generation-timestamp` AS eseTimestamp,
`shipment-pkg-number` AS pkgNumber,
`shipment-pkg-count` AS pkgCount,
`package-weight` pkgWeight,
`carrier-oid` AS carrierOid,
`svc-commit-timestamp` AS serviceCommitTimestamp,
`operational-scan-count` AS opScanCount,
`dim-volume-uom` AS dimWeightType,
`revenue-system-routing-cd` AS revSystemRouteCode,
`revenue-dt` AS revDate,
`unique_id`,
`last_update`,
`id`,
`cosmos-dspch-nbr` AS dispatchNbr,
`cer-id` AS cerId,
`lpar-state` AS lparState,
`lpar-disposition-state-cd` AS lparStateCode,
`return-type-cd` AS returnTypeCode,
`return-reason-group` AS returnReasonGroup,
`recipient-account-number` AS recipAccountNumber,
`shipper-tax-id-nbr` AS shipperTaxId
FROM
`track_db`.`shipment-profile`
WHERE
`ship-date`>20160201 and
`ursa-code` not like '%DACA' AND
`ursa-code` not like '%CGPA' AND
`ursa-code` not like '%ZYLA'
GROUP BY
`track-item-number`

我已经尝试过

    ALTER TABLE `track_db`.`shipment-profile` ADD KEY track_index(`track-item-number`, `ship-date`, `ursa-code`)  

但没有用:(

解释

# id, select_type, table, type, possible_keys, key, key_len, ref, rows, Extra
'1', 'SIMPLE', 'shipment-profile', 'ALL', 'track_index', NULL, NULL, NULL, '4609925', 'Using where; Using filesort'

可能返回 25,000 到 30,000 行。

我的 key_buffer_size 是 2 GB

MySQL 版本 5.6.29

做完之后

  ALTER TABLE `track_db`.`shipment-profile` ADD KEY track_index(`ship-date`, `track-item-number`)

解释一下

   # id, select_type, table, type, possible_keys, key, key_len, ref, rows, Extra
'1', 'SIMPLE', 'shipment-profile', 'ALL', 'track_index', NULL, NULL, NULL, '4610387', 'Using where; Using filesort'

现在使用 right('ursa-code', 4) 而不是 ('DACA', 'CGPA', 'ZYLA') 但没有太大改进解释一下

 # id, select_type, table,            type, possible_keys, key, key_len, ref,    rows,      Extra
'1', 'SIMPLE', 'shipment-profile', 'ALL', 'track_index', NULL, NULL, NULL, '4661631', 'Using where; Using filesort'

表状态命令

  table_name      |Engine|Version|Row_format|table_rows|Avg_row_length|Data_length|Max_data_length|Index_length|Data_free|Auto_increment|    Create_time    |    Update_time    |     Check_time    | table_collation|Checksum|Create_options|table_comment
shipment-profile|MyISAM| 10 | Dynamic | 4738574 | 727 | 2719772024|281474976710655|140731392 | 0 | 4738575 |2016-03-02 17:20:02|2016-03-05 10:55:40|2016-03-02 17:25:20| utf8_general_ci| | |

最佳答案

存在多个问题...

在提及其他非聚合列的同时对一列进行 GROUP BY 是不“正确的”。我认为你应该集中精力解决这个问题。也许您需要多个表来保存数据。

前导通配符不能使用索引——“%DACA”。

唯一可用的索引是 INDEX(ship-date),但这并不是很有用,正如您发现的 (ship-date, 跟踪项目编号)。

关于mysql - 带有MYISAM表引擎的MYSQL应该使用什么样的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35745083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com