Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> łaczenie tabel a explain, jeden join skutkuje tym ze zapytania odpala sie 16x szybciej
hostingekspert
post
Post #1





Grupa: Zarejestrowani
Postów: 51
Pomógł: 5
Dołączył: 12.04.2007
Skąd: 1=1

Ostrzeżenie: (0%)
-----


Witam,

mam sobie pewne zapytanie, zapytanie laczy sie z wieloma tabelami:

http://paste.ofcode.org/vQZM7Ffk4dg7b2WuCpUUKi

w tym z tabela users, ktora ma 10tsy uzytkownikow

jak zrobie EXPLAIN dla tego zapytania mam nastepujacy wynik:

http://awesomescreenshot.com/0664u4tkef

Dlaczego przy tabeli "u" pokazuje 10128 rows?

dodam ze cale zapytanie dla roznych przekazanych uzytkownikow odpala sie srednio 8-11sec ALE jak wywale

  1. u.id_facebook, u.id_user, u.name, u.email, u.gps

  1. LEFT JOIN users u ON m.id_sender = u.id_user


całość spada do 0.5sec.

Jak rozwiazac problem łączenia z tabela users i skad w explain tak duze wartosci dla tabeli users?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
Pyton_000
post
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


na obu polach masz klucz? (m.id_sender,, u.id_user)questionmark.gif
Go to the top of the page
+Quote Post
hostingekspert
post
Post #3





Grupa: Zarejestrowani
Postów: 51
Pomógł: 5
Dołączył: 12.04.2007
Skąd: 1=1

Ostrzeżenie: (0%)
-----


Tzn? oba pola zawsze sa wypelnione
Go to the top of the page
+Quote Post
Pyton_000
post
Post #4





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Czy masz pozakładane indeksy na te pola
Go to the top of the page
+Quote Post
hostingekspert
post
Post #5





Grupa: Zarejestrowani
Postów: 51
Pomógł: 5
Dołączył: 12.04.2007
Skąd: 1=1

Ostrzeżenie: (0%)
-----


indeksy mam nastepujace:

  1. ALTER TABLE `invitations`
  2. ADD PRIMARY KEY (`id_invitation`), ADD KEY `id_sender_idx` (`id_sender`), ADD KEY `id_category_idx` (`id_category`), ADD KEY `id_user_category_idx` (`id_user_category`), ADD KEY `id_subcategory_idx` (`id_subcategory`), ADD KEY `id_user_subcategory_idx` (`id_user_subcategory`);
  3.  
  4.  
  5. ALTER TABLE `invitations_deleted`
  6. ADD PRIMARY KEY (`id_invitation_delete`), ADD KEY `id_user_idx` (`id_user`), ADD KEY `id_invitation_idx` (`id_invitation`);
  7.  
  8. ALTER TABLE `invitation_recipients`
  9. ADD PRIMARY KEY (`id_invitation_recipient`), ADD KEY `id_recipient_idx` (`id_recipient`), ADD KEY `id_invitation_idx` (`id_invitation`);
Go to the top of the page
+Quote Post
Pyton_000
post
Post #6





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Ale nie widzę klucza na id_users w users
Go to the top of the page
+Quote Post
hostingekspert
post
Post #7





Grupa: Zarejestrowani
Postów: 51
Pomógł: 5
Dołączył: 12.04.2007
Skąd: 1=1

Ostrzeżenie: (0%)
-----


jak odpalam

  1. SELECT u.id_user, u.name, u.id_facebook, u.email, u.gps FROM users u WHERE id_user IN (SELECT id_friend FROM friends_relations WHERE id_user = 2)


w EXPLAIN takze mam

  1. PRIMARY u ALL NULL NULL NULL NULL 10047 USING WHERE
  2. DEPENDENT SUBQUERY friends_relations index_subquery id_user_idx,friends_relations_id_friend_users_id_u... friends_relations_id_friend_users_id_user 9 func 4 USING WHERE


a wiec "skanuje" cala tabele uzytkownikow?
Go to the top of the page
+Quote Post
sazian
post
Post #8





Grupa: Zarejestrowani
Postów: 1 045
Pomógł: 141
Dołączył: 19.09.2006
Skąd: B-tów

Ostrzeżenie: (0%)
-----


ALTER TABLE `users` ADD INDEX ( `id_user` ) ;
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 08:07