と という名前の 2 つの MySQL テーブルがstockin
ありstockout
ます。ここで、serialno という名前の一意の列の 2 つのテーブルをチェックして、在庫のある行を見つけたいと思います。2 つのテーブル間でランダムにルックアップするために、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)
ありがとう