Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> MySQL - wydajność - komplet danych, (Poza kluczem pola często są NULL)
beherit
post
Post #1





Grupa: Zarejestrowani
Postów: 28
Pomógł: 0
Dołączył: 29.07.2009

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


Mam pytanie z zakresu wydajnościowego - jak to lepiej napisać, aby każdy wiersz wyniku miał komplet danych i nie robić X podzapytań. Klucz jest nałożony na ts (timestamp) oraz v (identyfikator -> FK)
  1.  
  2. SELECT
  3. " . $this->_timestamp_db . ",
  4. IFNULL(a, (SELECT a FROM log_a_" . self::module_year . " WHERE a IS NOT NULL AND a NOT IN(' ', '1','807','1112','1111','111','11111','111111','22','1234') AND v= lv.v ORDER BY ts DESC LIMIT 1)) a,
  5. IFNULL(b, (SELECT b FROM log_a_" . self::module_year . " WHERE b IS NOT NULL AND v= lv.v AND ts < lv.ts ORDER BY ts DESC LIMIT 1)) b,
  6. IFNULL(c, (SELECT c FROM log_a_" . self::module_year . " WHERE c IS NOT NULL AND v= lv.v AND ts < lv.ts ORDER BY ts DESC LIMIT 1)) c,
  7. IFNULL(d, (SELECT d FROM log_a_" . self::module_year . " WHERE d IS NOT NULL AND v = lv.v AND ts < lv.ts ORDER BY ts DESC LIMIT 1)) d,
  8. IFNULL(e, (SELECT e FROM log_a_" . self::module_year . " WHERE e IS NOT NULL AND v = lv.v AND ts < lv.ts ORDER BY ts DESC LIMIT 1)) e,
  9. IFNULL(f, (SELECT f FROM log_a_" . self::module_year . " WHERE f IS NOT NULL AND v = lv.v AND ts < lv.ts ORDER BY ts DESC LIMIT 1)) f
  10. FROM
  11. log_a_" . self::module_year . " lv
  12. WHERE
  13. v= :v AND
  14. (
  15. lv.a IS NOT NULL OR
  16. lv.b IS NOT NULL OR
  17. lv.c IS NOT NULL OR
  18. lv.d IS NOT NULL OR
  19. lv.eIS NOT NULL OR
  20. lv.f IS NOT NULL
  21. ) AND
  22. ts >= " . $tstmp['timestamp_ms_last_cron'] . "
  23. ORDER BY ts ASC ";


Dodam, że tabela w tym momencie ma 10MB - maks planowane 100MB pola a,c,d,e,f to CHAR 8, a pole b: ENUM z czterema wartościami.

Ten post edytował beherit 26.04.2012, 07:41:36
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: 21.08.2025 - 05:09