ðͤФƤQ4, Q7ˤĤƤδñʹͻǤ.

#¾礻ǥ˥˥쥹ݥ󥹤äƤʤΤϡ(ȥ١)
#ץƥޥ줿̡
#(ǥåȤäƤΤǼºݤΥǡɤΨ褤Ȥޤ

Q4, Q7ʳˤĤƤϸǤʤ­(Ǽ)Τ̤ФƤޤ.

######
# Q4 #
######
xmark001
0.252s
--
xmark005
2.740s
--
xmark01
11.060s

SELECT
    xn4.docid,
    xn4.id
FROM
    xml_path xp3,
    xml_node xn3,
    xml_path p1_xp4,
    xml_node p1_xn4,
    xml_node xn4,
    xml_tag xt4
WHERE
    xp3.pathexp = '#/site#/closed_auctions#/closed_auction' AND
    xn3.pathid = xp3.pathid AND
    p1_xp4.pathexp = (xp3.pathexp || '#/price#/text()') AND
    p1_xn4.pathid = p1_xp4.pathid AND
    _int_flagment(p1_xn4.dewey,xn3.dewey) AND
    vchar2real(p1_xn4.value) >= 40.0 AND
    xn4.parent = xn3.id AND
    xn4.kind > 0 AND
    xn4.kind < 5 AND
    xt4.tagid = xn4.tagid AND
    xt4.name = 'price'

QUERY PLAN
Nested Loop  (cost=1.93..4705.32 rows=347 width=298) (actual time=24.40..11940.68 rows=670 loops=1)
  Join Filter: _int_flagment("inner".dewey, "outer".dewey)
  ->  Hash Join  (cost=1.93..2315.91 rows=6 width=239) (actual time=0.78..344.41 rows=975 loops=1)
        Hash Cond: ("outer".tagid = "inner".tagid)
        ->  Nested Loop  (cost=0.00..2311.59 rows=463 width=235) (actual time=0.48..305.46 rows=16575 loops=1)
              ->  Nested Loop  (cost=0.00..395.86 rows=500 width=219) (actual time=0.34..13.94 rows=975 loops=1)
                    ->  Nested Loop  (cost=0.00..11.07 rows=1 width=156) (actual time=0.30..0.31 rows=1 loops=1)
                          ->  Index Scan using xml_path_exp on xml_path xp3  (cost=0.00..5.53 rows=1 width=78) (actual time=0.20..0.21 rows=1 loops=1)
                                Index Cond: (pathexp = '#/site#/closed_auctions#/closed_auction'::character varying)
                          ->  Index Scan using xml_path_exp on xml_path p1_xp4  (cost=0.00..5.53 rows=1 width=78) (actual time=0.07..0.08 rows=1 loops=1)
                                Index Cond: (p1_xp4.pathexp = ("outer".pathexp || '#/price#/text()'::character varying))
                    ->  Index Scan using xml_node_pathid on xml_node xn3  (cost=0.00..371.91 rows=1030 width=63) (actual time=0.03..7.24 rows=975 loops=1)
                          Index Cond: (xn3.pathid = "outer".pathid)
              ->  Index Scan using xml_node_parent on xml_node xn4  (cost=0.00..3.63 rows=16 width=16) (actual time=0.03..0.17 rows=17 loops=975)
                    Index Cond: (xn4.parent = "outer".id)
                    Filter: ((kind > 0) AND (kind < 5))
        ->  Hash  (cost=1.93..1.93 rows=1 width=4) (actual time=0.23..0.23 rows=0 loops=1)
              ->  Seq Scan on xml_tag xt4  (cost=0.00..1.93 rows=1 width=4) (actual time=0.22..0.22 rows=1 loops=1)
                    Filter: (name = 'price'::character varying)
  ->  Index Scan using xml_node_pathid on xml_node p1_xn4  (cost=0.00..377.06 rows=343 width=59) (actual time=0.03..10.17 rows=670 loops=975)
        Index Cond: (p1_xn4.pathid = "outer".pathid)
        Filter: (vchar2real(value) >= 40::double precision)
Total runtime: 11942.17 msec

975NestedLoop.
Optimize...̤ΤȤɾФäȽξ
ܤϤʤΤ...

⤽Costactual timeγ⤤(?
ȥ١ץƥޥθ³ʤΤ׾̩ˤȤ褦
塼˥󥰤٤...

http://www.postgresql.jp/document/pg732doc/admin/routine-vacuuming.html#VACUUM-FOR-STATISTICS
#<OFFTOPIC>___Ū___٤׾äƤȤФޤ</OFFTOPIC>

#PostgreSQL 7.2 顢ANALYZE ϡƤιԤɤΤǤϤʤ
#ơ֥뤫˹ԤФ׽Ԥʤ褦ˤʤäᡢ
#ʥơ֥ФƤ⤫ʤ®˽褦ˤʤޤ
#ǤΤǡˤ˥ǡ١ΤФƼ¹Ԥ餯ʤñˤʤޤ
#
#    Tip: ñ̤Ǥ ANALYZE ¹٤Ĵ˼ŪȤϤΤǤϤޤ󤬡
#    	ñ̤Ĵ ANALYZE ǽפ׾ξܺ٥٥ǹԤʤȤϲͤ礬ޤ 
#    	WHERE ɤѤ졢ǡʬۤε§ۤȤɤʤϡ
#    	¾٤ǡٿʬۤɬפˤʤǤ礦
#    	ALTER TABLE SET STATISTICS 򻲾ȤƲ 

dewey_Ūˤ_դǤ뤬, IndexŽƤʤȤˤ꤬롣
deweyindexŽä˸̤ˤ⵿..
ŪparentpathΥǥåȤäƥե륿󥰤
ancestor, following, precedingǤϤΤ褦ʥե륿ʤ
礻ΨΤǥ󥷥diskreadۤ
ᤤ礬¿äˡǡǥȤʤ륱ˤơ

(ԲĤڻ뤹)Τ褦ʥץϥץƥޥǤ
ǥåưפƤΤ̵񤫤⤷ʤ(륳Ȥ˸礦?

http://www.postgresql.jp/document/pg732doc/reference/sql-analyze.html

deweyΤ褦ͤХ餱Ƥ硢ͤȼ褦ˤۤ褵..
ǥեȤо10ϺΥǤϡʤ..

Postgresϳĥ桼ؿΥȻФøʵ
(øʷи§

----------------------------------------------------------------

΢Ť褦ȯPostgresML...

>>   ¾ˤϡ7.3 ǤϡIN 䤤碌ͽ¬Ȥ⡢ºݤ 1 ʾʤ
>> 뤳ȤؤɤǡΨͤȡ䤤碌λѤˤʤ󤬤Τϡ
>> Ƥ⥢ץꥱ¦˿ɤȻפޤ

>Ȥ䤤碌η̤WHEREѤ硤WHEREŬ
>Ψͽ¬50%ˤʤäƤޤΤʤΤǤʤϡؿ
>̤WHEREɾƱȤޤˡ䤤碌η
>֥åܥåȤưʾϡ礦ʤ󤸤ʤʡ

>¸Τ褦ˡ7.4Ǥϡμ䤤碌Ÿ䤤
>碌ʤʤΤǡΤϤʤƤޤ

äȤΤ...⤷PostresΤܥȥͥå⤷ޤ...

---------------------------------------------------------------------------------------

######
# Q7 #
######
xmark001
0.186s
--
xmark005
5.599s
--
xmark01
25.340s

SELECT DISTINCT
    xn3.docid,
    xn3.id
FROM
    xml_path xp2,
    xml_node xn2,
    xml_node xn3
WHERE
    xp2.pathexp LIKE '#%/closed_auction' AND
    xn2.pathid = xp2.pathid AND
    xn3.parent = xn2.parent AND
    xn2.dewey < xn3.dewey AND
    xn3.kind > 0 AND
    xn3.kind < 5 AND
    xn3.kind = '1'

QUERY PLAN
Unique  (cost=2757.40..2812.13 rows=730 width=134) (actual time=28169.63..29337.02 rows=974 loops=1)
  ->  Sort  (cost=2757.40..2775.64 rows=7297 width=134) (actual time=28169.62..28819.71 rows=474825 loops=1)
        Sort Key: xn3.docid, xn3.id
        ->  Nested Loop  (cost=0.00..2289.17 rows=7297 width=134) (actual time=16.54..16944.41 rows=474825 loops=1)
              Join Filter: ("outer".dewey < "inner".dewey)
              ->  Nested Loop  (cost=0.00..412.56 rows=500 width=67) (actual time=14.49..34.20 rows=975 loops=1)
                    ->  Seq Scan on xml_path xp2  (cost=0.00..27.77 rows=1 width=4) (actual time=14.25..16.26 rows=1 loops=1)
                          Filter: (pathexp ~~ '#%/closed_auction'::text)
                    ->  Index Scan using xml_node_pathid on xml_node xn2  (cost=0.00..371.91 rows=1030 width=63) (actual time=0.23..11.30 rows=975 loops=1)
                          Index Cond: (xn2.pathid = "outer".pathid)
              ->  Index Scan using xml_node_parent on xml_node xn3  (cost=0.00..3.67 rows=5 width=67) (actual time=0.04..14.20 rows=975 loops=975)
                    Index Cond: (xn3.parent = "outer".parent)
                    Filter: ((kind > 0) AND (kind < 5) AND (kind = 1::smallint))
Total runtime: 34525.41 msec

474,825Υ(distinct)˻֤äƤ롣
PostgresΥѥХåե16MBƤƤʤͳΤҤȤġ
ȼΤŤʤΤפʤʬ⤢
(PostgresΥȤΥ르ꥺब褯ʤ?

1). docididindexŽ¿ʤ뤫Τʤͤȹޤʤ
2). 뤤, ȥХåե¿Ƥ
3). distinctȤȼΤͤʤ -> , XPath1.0λͤǤϥΡɤνʣϤʤ
	(XPath2.0ȥ󥹥١ǽʣ. ͤ㤦...

Sort Memory Size

When sorting large tables or results, PostgreSQL will sort them in parts, 
placing intermediate results in temporary files. 
These files are then merged and resorted until all rows are sorted. 
Increasing the batch size creates fewer temporary files and often allows faster sorting. 
However, if the sort batches are too large, they cause pageins 
because parts of the sort batch get paged out to swap during sorting. 
In these cases, it is much faster to use smaller sort batches and more temporary files,
so again, swap pageins determine when too much memory has been allocated. 
Keep in mind that this parameter is used for every backend performing a sort, 
either for ORDER BY, CREATE INDEX or for a merge join. 
Several simultaneous sorts will use several times this amount of memory.

http://www.linuxjournal.com/article.php?sid=4791
