aika Posted April 22, 2013 Report Share Posted April 22, 2013 problēma: esošais (acīmredzot patizlais) pieprasījums pārsniedz 5s. SELECT * FROM a INNER JOIN b ON b.id = a.id LEFT JOIN c ON c.id = b.c_id WHERE a.u_id = 'f53c6deff44e23439d2b84d26820cec9' ORDER BY a.c, a.e LIMIT 0, 25; kā, lūdzu, nooptimizēt?! a tabula ~ 10K, b tabula ~ 50k, c tabula ~ 100 ierakstu. visi id varchar(32) ar indeksiem paldies jau iepriekš! Quote Link to comment Share on other sites More sharing options...
l27 Posted April 22, 2013 Report Share Posted April 22, 2013 (edited) 1) * vietā saliec tos laukus, kurus patiešam vajag 2) uztaisi indeksu, kura iekļāuj a.u_id (4 chari), a.id un selectā iekļaujamos laukus, ja tie nav text 3) jabūt indeksam b.id un b.c_id 4) tik nīkulīgām tabulām id vajadzētu smallint Edited April 22, 2013 by l27 Quote Link to comment Share on other sites More sharing options...
daGrevis Posted April 22, 2013 Report Share Posted April 22, 2013 Arī nesaprotu, kāpēc PK ir strings... Quote Link to comment Share on other sites More sharing options...
rpr Posted April 22, 2013 Report Share Posted April 22, 2013 explain arī rāda, ka indeksi tiek ņemti vērā? tabulu izmērs tāds, kas sāk izmest pirmos performances trūkumus. Quote Link to comment Share on other sites More sharing options...
l27 Posted April 22, 2013 Report Share Posted April 22, 2013 1) id saliec int tipu 2) selectā liec tikai kolonnas, kas vajadzīgas Quote Link to comment Share on other sites More sharing options...
marrtins Posted April 22, 2013 Report Share Posted April 22, 2013 Iedo sistēmas un mysql root, saoptimizēšu vai arī pateikšu, kas trūkst :) Quote Link to comment Share on other sites More sharing options...
aika Posted April 23, 2013 Author Report Share Posted April 23, 2013 * aizstāšana ieekonomēja ~ 2 sekundes. txs par to. diemžēl ID tipus vairs mainīt nav iespējams. Quote Link to comment Share on other sites More sharing options...
l27 Posted April 23, 2013 Report Share Posted April 23, 2013 uz id indeksa uzliec garumu 4. Ja tie ir primary key, tad noņem. No šāda pasākuma būs jēgas, ja id pirmie 4 simboli ir daudzmaz unikāli. Quote Link to comment Share on other sites More sharing options...
Val Posted April 23, 2013 Report Share Posted April 23, 2013 (edited) varchar(32) diemžēl ID tipus vairs mainīt nav iespējams. Raiņa kopotus rakstu tur mēģini sarakstīt? Rādi redzēt, ko atgriež EXPLAIN SELECT * FROM a INNER JOIN b ON b.id = a.id LEFT JOIN c ON c.id = b.c_id WHERE a.u_id = 'f53c6deff44e23439d2b84d26820cec9' ORDER BY a.c, a.e LIMIT 0, 25; Edited April 23, 2013 by Val Quote Link to comment Share on other sites More sharing options...
blackhalt Posted April 23, 2013 Report Share Posted April 23, 2013 Šis ir MD5 f53c6deff44e23439d2b84d26820cec9 Tas tā, FYI. Quote Link to comment Share on other sites More sharing options...
aika Posted April 23, 2013 Author Report Share Posted April 23, 2013 uz id indeksa uzliec garumu 4. Ja tie ir primary key, tad noņem. No šāda pasākuma būs jēgas, ja id pirmie 4 simboli ir daudzmaz unikāli. ID ir primary. ko nozīmē - daudz maz unikāli? Kāpēc ņemt nost primary?! Quote Link to comment Share on other sites More sharing options...
aika Posted April 23, 2013 Author Report Share Posted April 23, 2013 (edited) Nomainot php kodu tiku vaļā no viena innera, tomēr joprojām ~ 4s. EXPLAIN SELECT a.id, a.t, a.e, a.u, a.r, a.wFROM aINNER JOIN b ON b.a_id = a.idWHERE b.u_id = 'f53c6deff44e23439d2b84d26820cec9'ORDER BY a.c, a.eLIMIT 0 , 25 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE a ALL NULL NULL NULL NULL 60358 Using filesort 1 SIMPLE b ref a_id,u_id,abi a_id 98 func 1 Using where `abi` ir dubultiindekss a_id un u_id P.S. lauku un tabulu nosaukumi mainīti P.S.S. tabula nogļukoja, sory Edited April 23, 2013 by aika Quote Link to comment Share on other sites More sharing options...
l27 Posted April 23, 2013 Report Share Posted April 23, 2013 (edited) ID ir primary. ko nozīmē - daudz maz unikāli? Kāpēc ņemt nost primary?! 1) Ja visiem ierakstiem pirmie 4 simboli ir identiski, tad no indeksa uz šiem simbolim nebūs jēga 2) nav jegas no primary, ja tas ir 32 baiti garš. Edited April 23, 2013 by l27 Quote Link to comment Share on other sites More sharing options...
marrtins Posted April 23, 2013 Report Share Posted April 23, 2013 Nav nekādu problēmu izmantot md5 hashu kā primary tik relatīvi maz datiem. Uzliec index uz a.id,a.c, a.e Quote Link to comment Share on other sites More sharing options...
aika Posted April 24, 2013 Author Report Share Posted April 24, 2013 pilnīgi neko nedeva. a tabulai expleins norāda null possible keys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.