gpt4 book ai didi

mysql - 两个mysql表之间随机查找的正确索引

转载 作者:行者123 更新时间:2023-11-30 01:36:19 25 4
gpt4 key购买 nike

我有两个 MySQL 表,名为 stockinstockout。现在我想检查两个表中名为serialno 的唯一列,以查找现有库存行。我尝试了 4 个选择查询行来在两个表之间进行随机查找。但是,每个查询都需要花费太多时间来执行。你能检查一下表的表索引是否有错误的问题吗?如果您有任何更正或建议,我将不胜感激。

mysql> SHOW INDEX FROM stockin\G
*************************** 1. row ***************************
Table: stockin
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: stockin_id
Collation: A
Cardinality: 14657
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: stockin
Non_unique: 1
Key_name: shiptype
Seq_in_index: 1
Column_name: shiptype
Collation: A
Cardinality: 18
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 3. row ***************************
Table: stockin
Non_unique: 1
Key_name: userid
Seq_in_index: 1
Column_name: userid
Collation: A
Cardinality: 22
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 4. row ***************************
Table: stockin
Non_unique: 1
Key_name: uom
Seq_in_index: 1
Column_name: uom
Collation: A
Cardinality: 10
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 5. row ***************************
Table: stockin
Non_unique: 1
Key_name: warehouseid
Seq_in_index: 1
Column_name: warehouse_id
Collation: A
Cardinality: 6
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 6. row ***************************
Table: stockin
Non_unique: 1
Key_name: project_id_for_stockin
Seq_in_index: 1
Column_name: project_id
Collation: A
Cardinality: 2
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 7. row ***************************
Table: stockin
Non_unique: 1
Key_name: cus_id
Seq_in_index: 1
Column_name: cus_id
Collation: A
Cardinality: 2
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
7 rows in set (0.01 sec)

mysql> SHOW INDEX FROM stockout\G
*************************** 1. row ***************************
Table: stockout
Non_unique: 0
Key_name: PRIMARY
Seq_in_index: 1
Column_name: stockout_id
Collation: A
Cardinality: 19654
Sub_part: NULL
Packed: NULL
Null:
Index_type: BTREE
Comment:
Index_comment:
*************************** 2. row ***************************
Table: stockout
Non_unique: 1
Key_name: eng_id
Seq_in_index: 1
Column_name: eng_id
Collation: A
Cardinality: 5
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 3. row ***************************
Table: stockout
Non_unique: 1
Key_name: project_id
Seq_in_index: 1
Column_name: project_id
Collation: A
Cardinality: 9
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 4. row ***************************
Table: stockout
Non_unique: 1
Key_name: warehouseid
Seq_in_index: 1
Column_name: warehouseid
Collation: A
Cardinality: 47
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 5. row ***************************
Table: stockout
Non_unique: 1
Key_name: response_type_id
Seq_in_index: 1
Column_name: response_type_id
Collation: A
Cardinality: 5
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 6. row ***************************
Table: stockout
Non_unique: 1
Key_name: cus_id
Seq_in_index: 1
Column_name: cus_id
Collation: A
Cardinality: 1
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 7. row ***************************
Table: stockout
Non_unique: 1
Key_name: employee_id
Seq_in_index: 1
Column_name: employee_id
Collation: A
Cardinality: 19
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 8. row ***************************
Table: stockout
Non_unique: 1
Key_name: userid
Seq_in_index: 1
Column_name: userid
Collation: A
Cardinality: 1
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
*************************** 9. row ***************************
Table: stockout
Non_unique: 1
Key_name: uom
Seq_in_index: 1
Column_name: uom
Collation: A
Cardinality: 11
Sub_part: NULL
Packed: NULL
Null: YES
Index_type: BTREE
Comment:
Index_comment:
9 rows in set (0.02 sec)

谢谢

最佳答案

我已经解决了两个表之间的随机查找,以添加随机检查中唯一列的索引。我已经在索引中添加了列,如下面的代码,并且立即添加。我对结果执行时间感到惊讶。该查询花费了超过 3.30 分钟,当我添加索引时,只花费了 0.03 秒。

CREATE INDEX columnname ON tablename(columnname)

关于mysql - 两个mysql表之间随机查找的正确索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16828232/

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