За последние 24 часа нас посетил 22061 программист и 1310 роботов. Сейчас ищут 977 программистов ...

postgreSQL - представления VS обычные запросы.

Тема в разделе "PostgreSQL", создана пользователем DarkElf, 1 июн 2008.

  1. DarkElf

    DarkElf Активный пользователь

    С нами с:
    22 окт 2006
    Сообщения:
    1.632
    Симпатии:
    0
    Собственно, вопрос в чем. Как я понимаю, представления должны работать быстрее, так как хранятся непосредственно на сервере, и он не должен тратить время на их обработку.
    ОДНАКО:

    Код (Text):
    1.  
    2. C:\wwwserver\Apache2\bin>ab -n 25000 -c 64 http://localhost/pgsql.php
    3.  
    4. Server Software:        Apache/2.0.61
    5. Server Hostname:        localhost
    6. Server Port:            80
    7.  
    8. Document Path:          /pgsql.php
    9. Document Length:        457 bytes
    10.  
    11. Concurrency Level:      64
    12. Time taken for tests:   131.359375 seconds
    13. Complete requests:      25000
    14. Failed requests:        24936
    15.    (Connect: 0, Length: 24936, Exceptions: 0)
    16. Write errors:           0
    17. Total transferred:      7796312 bytes
    18. HTML transferred:       3121312 bytes
    19. Requests per second:    190.32 [#/sec] (mean)
    20. Time per request:       336.280 [ms] (mean)
    21. Time per request:       5.254 [ms] (mean, across all concurrent requests)
    22. Transfer rate:          57.96 [Kbytes/sec] received
    23.  
    24.  
    25. C:\wwwserver\Apache2\bin>ab -n 25000 -c 64 http://localhost/pgsql.php
    26.  
    27. Server Software:        Apache/2.0.61
    28. Server Hostname:        localhost
    29. Server Port:            80
    30.  
    31. Document Path:          /pgsql.php
    32. Document Length:        124 bytes
    33.  
    34. Concurrency Level:      64
    35. Time taken for tests:   128.390625 seconds
    36. Complete requests:      25000
    37. Failed requests:        1
    38.    (Connect: 0, Length: 1, Exceptions: 0)
    39. Write errors:           0
    40. Total transferred:      7775331 bytes
    41. HTML transferred:       3100331 bytes
    42. Requests per second:    194.72 [#/sec] (mean)
    43. Time per request:       328.680 [ms] (mean)
    44. Time per request:       5.136 [ms] (mean, across all concurrent requests)
    45. Transfer rate:          59.14 [Kbytes/sec] received
    в первом случае вызывалось представление, во втором случае - прямо запрос.

    [sql]
    SELECT
    regions.name AS region,
    countryes.name AS country,
    city.name AS city
    FROM
    ((regions LEFT JOIN countryes ON ((regions.country_id = countryes.id)))
    LEFT JOIN city ON ((regions.id = city.region)))
    [/sql]

    P.S. запрос сформирован при помощи EMS PostgreSQL Manager последней версии

    P.S.S. Единственное, при втором тесте процессов постгреса склонировалось раза в два больше. рестарта сервера между тестами я не делал. AMD Semprone 2800+ (1.6 Реально), 1,5Гб оперативки. Памяти завались, проц - 100%. Соединение с постгрессом открыто через pg_pconnect()


    Оно собственно так и должно быть?