J'ai cette update
requête:Comprendre EXPLIQUEZ pour créer un index de colonne basée sur
explain UPDATE
qanda AS ans1
JOIN qanda AS ans2 ON ans2.related = ans1.related
JOIN qanda AS ques ON ans2.related = ques.id
SET ans1.acceptedanswer = IF(ans1.id <> 3, 0, IFNULL(ans1.acceptedanswer, 0)^b'1'),
ans1.aadate = IF(ans1.id <> 3, ans1.aadate, 4353)
WHERE ques.author_id = 29
AND ans2.id = 3
AND ans2.author_id = 31
AND (ques.amount IS NULL or ans1.acceptedanswer IS NULL)
Et voici le résultat de son EXPLAIN
:
+------+-------------+-------+-------+---------------------------+---------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+-------+---------------------------+---------+---------+-------+------+-------------+
| 1 | SIMPLE | ans2 | const | PRIMARY,author_id,related | PRIMARY | 4 | const | 1 | NULL |
| 2 | SIMPLE | ques | const | PRIMARY,author_id | PRIMARY | 4 | const | 1 | NULL |
| 3 | SIMPLE | ans1 | ALL | related | NULL | NULL | NULL | 4 | Using where |
+------+-------------+-------+-------+---------------------------+---------+---------+-------+------+-------------+
Il convient de noter ma table est juste contenant 4 rangées de données.
Est-ce que ma structure est bonne? Ou devrais-je créer un tel index sur une telle colonne?
lancer une tonne de lignes avec un db de test qui a un nombre important de lignes. Maintenant vous n'êtes pas. En ce moment, votre explication n'a pas de sens. – Drew