Image
Top
Navigation

OrientDBでSQLを実行してみよう!

サンプルデータベースを使ってSQLを試してみる

それではOrientDBで実際にいくつかのクエリを実行してみましょう。
OrientDBにはサンプルデータベースとして ‘GratefulDeadConcerts’ が作成されています。
こちらを利用して幾つかのSQLを実行していきたいと思います。

0. はじめに

まず、GratefulDeadConcerts のデータベースの中身ですが、こちらはアメリカの伝説的なロックバンド”Grateful Dead”のライブの情報をグラフで定義したデータベースです。

このデータベースで学習を進めるにあたり、’Grateful Dead’ に関して知っておいたほうがよい情報としてはGrateful Deadはジェリー・ガルシア率いる非常にライブ活動に熱心なバンドというところです。

データベース自体は非常にシンプルなデータ構造のグラフですので学習には最適かと思います。

1. サンプルデータベースへの接続

それでは、まずGratefulDeadConcertsデータベースへ接続します

ローカル接続

それではまずコンソールツールを使用してローカルのデータベースへConsoleから直接接続します。

connect plocal:../databases/GratefulDeadConcerts admin admin

Connecting to database [plocal:../databases/GratefulDeadConcerts] with user 'admin'...OK

正しく接続できれば

Connecting to database [plocal:../databases/GratefulDeadConcerts] with user 'admin'...OK

orientdb> connect remote:localhost root

と表示ます。
いったん切断したいと思うので disconnect を入力して切断してください。

orientdb> disconnect
Disconnecting from the database [GratefulDeadConcerts]...OK

と表示され無事切断できました。

リモート接続

次にはリモートサーバー上にある OrientDB への接続方法を試します。

connect remote:127.0.0.1/GratefulDeadConcerts admin admin
Connecting to database [remote:127.0.0.1/GratefulDeadConcerts] with user 'admin'...OK

と表示され無事接続できました。

info コマンドによるデータベース情報の表示

それでは、実際にデータベースの中身をみてみましょう

まずは info コマンドを入寮してDBの中身をみてみます。

orientdb {GratefulDeadConcerts}> info

Current database: GratefulDeadConcerts (url=remote:localhost/GratefulDeadConcerts)

DISTRIBUTED CONFIGURATION: none (OrientDB is running in standalone mode)

DATABASE PROPERTIES
--------------------------------+----------------------------------------------------+
 NAME                           | VALUE                                              |
--------------------------------+----------------------------------------------------+
 Name                           | null                                               |
 Version                        | 9                                                  |
 Date format                    | yyyy-MM-dd                                         |
 Datetime format                | yyyy-MM-dd HH:mm:ss                                |
 Timezone                       | GMT                                                |
 Locale Country                 | UK                                                 |
 Locale Language                | EN                                                 |
 Charset                        | UTF-8                                              |
 Schema RID                     | #0:1                                               |
 Index Manager RID              | #0:2                                               |
 Dictionary RID                 | null                                               |
--------------------------------+----------------------------------------------------+

CLUSTERS
----------------------------------------------+-------+---------------------+---------+-----------------+
 NAME                                         |   ID  | TYPE                | DATASEG | RECORDS         |
----------------------------------------------+-------+---------------------+---------+-----------------+
 _studio_bookmark                             |    12 | PHYSICAL            |      -1 |               0 |
 default                                      |     3 | PHYSICAL            |      -1 |               0 |
 e                                            |    10 | PHYSICAL            |      -1 |               0 |
 followed_by                                  |    11 | PHYSICAL            |      -1 |            7047 |
 index                                        |     1 | PHYSICAL            |      -1 |               2 |
 internal                                     |     0 | PHYSICAL            |      -1 |               3 |
 manindex                                     |     2 | PHYSICAL            |      -1 |               1 |
 ofunction                                    |     7 | PHYSICAL            |      -1 |               0 |
 orids                                        |     6 | PHYSICAL            |      -1 |               0 |
 orole                                        |     4 | PHYSICAL            |      -1 |               3 |
 oschedule                                    |     8 | PHYSICAL            |      -1 |               0 |
 ouser                                        |     5 | PHYSICAL            |      -1 |               3 |
 v                                            |     9 | PHYSICAL            |      -1 |             809 |
----------------------------------------------+-------+---------------------+---------+-----------------+
 TOTAL = 13                                                                 |         |            7868 |
----------------------------------------------------------------------------+---------+-----------------+

CLASSES
----------------------------------------------+------------------------------------+------------+----------------+
 NAME                                         | SUPERCLASS                         | CLUSTERS   | RECORDS        |
----------------------------------------------+------------------------------------+------------+----------------+
 _studio_bookmark                             |                                    | 12         |              0 |
 E                                            |                                    | 10         |              0 |
 followed_by                                  | E                                  | 11         |           7047 |
 OFunction                                    |                                    | 7          |              0 |
 OIdentity                                    |                                    | -          |              0 |
 ORestricted                                  |                                    | -          |              0 |
 ORIDs                                        |                                    | 6          |              0 |
 ORole                                        | OIdentity                          | 4          |              3 |
 OSchedule                                    |                                    | 8          |              0 |
 OTriggered                                   |                                    | -          |              0 |
 OUser                                        | OIdentity                          | 5          |              3 |
 V                                            |                                    | 9          |            809 |
----------------------------------------------+------------------------------------+------------+----------------+
 TOTAL = 12                                                                                                 7862 |
----------------------------------------------+------------------------------------+------------+----------------+

INDEXES
----------------------------------------------+------------+-----------------------+----------------+------------+
 NAME                                         | TYPE       |         CLASS         |     FIELDS     | RECORDS    |
----------------------------------------------+------------+-----------------------+----------------+------------+
 dictionary                                   | DICTIONARY |                       |                |          0 |
 ORole.name                                   | UNIQUE     | ORole                 | name           |          3 |
 OUser.name                                   | UNIQUE     | OUser                 | name           |          3 |
----------------------------------------------+------------+-----------------------+----------------+------------+
 TOTAL = 3                                                                                                     6 |
-----------------------------------------------------------------------------------------------------------------+
orientdb {GratefulDeadConcerts}>

2. SQL コマンドの実行

全ノードの取得するSelect文を書く

まずは全てのvertices(ノード) を取得してみましょう

orientdb {GratefulDeadConcerts}> select * from V

----+-----+------+---------+---------+----------+-----------+------------+-------------+-------------+--------------+--------------------------
#   |@RID |type  |song_type|in_sung_b|out_sung_b|performance|in_written_b|out_written_b|in_followed_b|out_followed_b|name
----+-----+------+---------+---------+----------+-----------+------------+-------------+-------------+--------------+--------------------------
0   |#9:0 |null  |null     |null     |null      |null       |null        |null         |null         |null          |null
1   |#9:1 |song  |cover    |null     |#9:8      |5          |null        |#9:7         |[size=4]     |[size=5]      |HEY BO DIDDLEY
2   |#9:2 |song  |cover    |null     |#9:9      |1          |null        |#9:9         |[size=2]     |[size=2]      |IM A MAN
3   |#9:3 |song  |cover    |null     |#9:50     |531        |null        |#9:27        |[size=65]    |[size=84]     |NOT FADE AWAY
4   |#9:4 |song  |original |null     |#9:8      |394        |null        |#9:93        |[size=76]    |[size=53]     |BERTHA
5   |#9:5 |song  |cover    |null     |#9:8      |293        |null        |#9:131       |[size=46]    |[size=39]     |GOING DOWN THE ROAD FEE...
6   |#9:6 |song  |cover    |null     |#9:50     |1          |null        |#9:7         |[size=2]     |[size=2]      |MONA
7   |#9:7 |artist|null     |[size=7] |null      |null       |[size=9]    |null         |null         |null          |Bo_Diddley
8   |#9:8 |artist|null     |[size=...|null      |null       |[size=4]    |null         |null         |null          |Garcia
9   |#9:9 |artist|null     |[size=2] |null      |null       |#9:2        |null         |null         |null          |Spencer_Davis
10  |#9:10|song  |original |null     |#9:50     |473        |null        |#9:93        |[size=99]    |[size=79]     |JACK STRAW
11  |#9:11|song  |original |null     |#9:335    |24         |null        |#9:350       |[size=20]    |[size=14]     |JAM
12  |#9:12|song  |original |null     |#9:8      |312        |null        |#9:93        |[size=33]    |[size=47]     |CASEY JONES
13  |#9:13|song  |original |null     |#9:8      |423        |null        |#9:93        |[size=65]    |[size=80]     |DEAL
14  |#9:14|song  |original |null     |#9:223    |519        |null        |#9:93        |[size=94]    |[size=60]     |TRUCKING
15  |#9:15|song  |null     |null     |null      |null       |null        |null         |[size=27]    |[size=46]     |BABY BLUE
16  |#9:16|song  |original |null     |#9:335    |1386       |null        |#9:335       |[size=92]    |[size=73]     |DRUMS
17  |#9:17|song  |original |null     |#9:8      |328        |null        |#9:93        |[size=46]    |[size=31]     |STELLA BLUE
18  |#9:18|song  |null     |null     |null      |null       |null        |null         |#11:14       |#11:7007      |MOUNTAIN JAM
19  |#9:19|song  |cover    |null     |#9:50     |427        |null        |#9:245       |[size=86]    |[size=87]     |PROMISED LAND
----+-----+------+---------+---------+----------+-----------+------------+-------------+-------------+--------------+--------------------------
LIMIT EXCEEDED: resultset contains more items not displayed (limit=20)

20 item(s) found. Query executed in 0.195 sec(s).

以下の結果か取得できます。

次はバンドリーダーである Garcia のデータを取得してみましょう。

select * from V where name='Garcia'

結果はこちらです。

orientdb {GratefulDeadConcerts}> select * from V where name='Garcia'

----+----+------+----------+-------------+------
#   |@RID|name  |in_sung_by|in_written_by|type
----+----+------+----------+-------------+------
0   |#9:8|Garcia|[size=146]|[size=4]     |artist
----+----+------+----------+-------------+------

1 item(s) found. Query executed in 0.083 sec(s).

RID を指定して Garcia の情報を取得する場合は以下です。

select * from V where @rid=#9:8
orientdb {GratefulDeadConcerts}> select * from V where @rid=#9:8

----+----+----------+-------------+------+------
#   |@RID|in_sung_by|in_written_by|name  |type
----+----+----------+-------------+------+------
0   |#9:8|[size=146]|[size=4]     |Garcia|artist
----+----+----------+-------------+------+------

1 item(s) found. Query executed in 0.038 sec(s).

以下の書き方も可能です。

select * from #9:8 
select from #9:8 

#厳密には*を省略する場合は意味が異なります。こちらを参照してください。

さて次は 10回以上演奏されたものを取得しましょう
performances

select * from V where type = 'song’ and performances > 10
orientdb {GratefulDeadConcerts}> select * from V where type = 'song' and performances > 10

----+-----+------------+----+--------------+-------------------------------+---------+---------------+--------------+-----------
#   |@RID |performances|type|in_followed_by|name                           |song_type|out_followed_by|out_written_by|out_sung_by
----+-----+------------+----+--------------+-------------------------------+---------+---------------+--------------+-----------
0   |#9:3 |531         |song|[size=65]     |NOT FADE AWAY                  |cover    |[size=84]      |#9:27         |#9:50
1   |#9:4 |394         |song|[size=76]     |BERTHA                         |original |[size=53]      |#9:93         |#9:8
2   |#9:5 |293         |song|[size=46]     |GOING DOWN THE ROAD FEELING BAD|cover    |[size=39]      |#9:131        |#9:8
3   |#9:10|473         |song|[size=99]     |JACK STRAW                     |original |[size=79]      |#9:93         |#9:50
4   |#9:11|24          |song|[size=20]     |JAM                            |original |[size=14]      |#9:350        |#9:335
5   |#9:12|312         |song|[size=33]     |CASEY JONES                    |original |[size=47]      |#9:93         |#9:8
6   |#9:13|423         |song|[size=65]     |DEAL                           |original |[size=80]      |#9:93         |#9:8
7   |#9:14|519         |song|[size=94]     |TRUCKING                       |original |[size=60]      |#9:93         |#9:223
8   |#9:16|1386        |song|[size=92]     |DRUMS                          |original |[size=73]      |#9:335        |#9:335
9   |#9:17|328         |song|[size=46]     |STELLA BLUE                    |original |[size=31]      |#9:93         |#9:8
10  |#9:19|427         |song|[size=86]     |PROMISED LAND                  |cover    |[size=87]      |#9:245        |#9:50
11  |#9:20|325         |song|[size=65]     |BEAT IT ON DOWN THE LINE       |cover    |[size=60]      |#9:169        |#9:50
12  |#9:21|241         |song|[size=59]     |COLD RAIN AND SNOW             |cover    |[size=56]      |#9:131        |#9:8
13  |#9:22|332         |song|[size=60]     |UNCLE JOHNS BAND               |original |[size=49]      |#9:93         |#9:8
14  |#9:23|582         |song|[size=107]    |PLAYING IN THE BAND            |original |[size=94]      |#9:93         |#9:183
15  |#9:25|594         |song|[size=77]     |SUGAR MAGNOLIA                 |original |[size=90]      |#9:358        |#9:50
16  |#9:26|340         |song|[size=57]     |ONE MORE SATURDAY NIGHT        |original |[size=79]      |#9:50         |#9:50
17  |#9:28|234         |song|[size=7]      |MISSISSIPPI HALF-STEP          |original |[size=7]       |#9:93         |#9:8
18  |#9:29|65          |song|[size=32]     |HERE COMES SUNSHINE            |original |[size=34]      |#9:93         |#9:8
19  |#9:30|36          |song|[size=9]      |I FOUGHT THE LAW               |cover    |[size=9]       |#9:405        |#9:8
----+-----+------------+----+--------------+-------------------------------+---------+---------------+--------------+-----------
LIMIT EXCEEDED: resultset contains more items not displayed (limit=20)

20 item(s) found. Query executed in 0.138 sec(s).

集計関数count()

OrientDBにはSQLの知識を持っている方には馴染み深いいくつかの関数が使用可能です。
試しに、count()関数を使用して ‘song’ が何件登録されているか確認してみます。

select count(*) from V where type='song'
orientdb {GratefulDeadConcerts}> select count(*) from V where type = 'song'

----+-----+-----
#   |@RID |count
----+-----+-----
0   |#-2:0|584
----+-----+-----

1 item(s) found. Query executed in 0.055 sec(s).

traverse

次にトラバースしてみます。
それでは Garcia が歌った演奏を抽出してみます。

traverse in_sung_by from (select * from V where @rid = #9:8)

orientdb {GratefulDeadConcerts}> traverse in_sung_by from (select * from V where @rid = #9:8)

----+-----+------+---------+---------+----------+-----------+------------+-------------+-------------+--------------+--------------------------
#   |@RID |type  |song_type|in_sung_b|out_sung_b|performance|in_written_b|out_written_b|in_followed_b|out_followed_b|name
----+-----+------+---------+---------+----------+-----------+------------+-------------+-------------+--------------+--------------------------
0   |#9:8 |artist|null     |[size=...|null      |null       |[size=4]    |null         |null         |null          |Garcia
1   |#9:1 |song  |cover    |null     |#9:8      |5          |null        |#9:7         |[size=4]     |[size=5]      |HEY BO DIDDLEY
2   |#9:4 |song  |original |null     |#9:8      |394        |null        |#9:93        |[size=76]    |[size=53]     |BERTHA
3   |#9:5 |song  |cover    |null     |#9:8      |293        |null        |#9:131       |[size=46]    |[size=39]     |GOING DOWN THE ROAD FEE...
4   |#9:12|song  |original |null     |#9:8      |312        |null        |#9:93        |[size=33]    |[size=47]     |CASEY JONES
5   |#9:13|song  |original |null     |#9:8      |423        |null        |#9:93        |[size=65]    |[size=80]     |DEAL
6   |#9:17|song  |original |null     |#9:8      |328        |null        |#9:93        |[size=46]    |[size=31]     |STELLA BLUE
7   |#9:21|song  |cover    |null     |#9:8      |241        |null        |#9:131       |[size=59]    |[size=56]     |COLD RAIN AND SNOW
8   |#9:22|song  |original |null     |#9:8      |332        |null        |#9:93        |[size=60]    |[size=49]     |UNCLE JOHNS BAND
9   |#9:28|song  |original |null     |#9:8      |234        |null        |#9:93        |[size=7]     |[size=7]      |MISSISSIPPI HALF-STEP
10  |#9:29|song  |original |null     |#9:8      |65         |null        |#9:93        |[size=32]    |[size=34]     |HERE COMES SUNSHINE
11  |#9:30|song  |cover    |null     |#9:8      |36         |null        |#9:405       |[size=9]     |[size=9]      |I FOUGHT THE LAW
12  |#9:32|song  |cover    |null     |#9:8      |12         |null        |#9:403       |[size=7]     |[size=6]      |WEREWOLVES OF LONDON
13  |#9:34|song  |original |null     |#9:8      |48         |null        |#9:93        |[size=19]    |[size=15]     |ATTICS OF MY LIFE
14  |#9:36|song  |original |null     |#9:8      |87         |null        |#9:93        |[size=37]    |[size=39]     |FOOLISH HEART
15  |#9:43|song  |original |null     |#9:8      |163        |null        |#9:93        |[size=54]    |[size=50]     |SHAKEDOWN STREET
16  |#9:44|song  |original |null     |#9:8      |56         |null        |#9:93        |[size=11]    |[size=16]     |LIBERTY
17  |#9:45|song  |original |null     |#9:8      |323        |null        |#9:93        |[size=5]     |[size=4]      |US BLUES
18  |#9:48|song  |original |null     |#9:8      |296        |null        |#9:93        |[size=22]    |[size=29]     |BIRDSONG
19  |#9:49|song  |cover    |null     |#9:8      |185        |null        |#9:131       |[size=66]    |[size=58]     |IKO IKO
----+-----+------+---------+---------+----------+-----------+------------+-------------+-------------+--------------+--------------------------
LIMIT EXCEEDED: resultset contains more items not displayed (limit=20)

147 item(s) found. Traverse executed in 0.011 sec(s).

うまくいったかなとも思いましたが、この条件だと artist も入ってきてしまいますのでtypeをsongのみに絞ります.

select * from (traverse in_sung_by from (select * from V where @rid=#9:8)) where type='song'
orientdb {GratefulDeadConcerts}> select * from (traverse in_sung_by from (select * from V where @rid=#9:8)) where type='song'

----+-----+----+-------------------------------+---------+------------+---------------+--------------+-----------+--------------
#   |@RID |type|name                           |song_type|performances|out_followed_by|out_written_by|out_sung_by|in_followed_by
----+-----+----+-------------------------------+---------+------------+---------------+--------------+-----------+--------------
0   |#9:1 |song|HEY BO DIDDLEY                 |cover    |5           |[size=5]       |#9:7          |#9:8       |[size=4]
1   |#9:4 |song|BERTHA                         |original |394         |[size=53]      |#9:93         |#9:8       |[size=76]
2   |#9:5 |song|GOING DOWN THE ROAD FEELING BAD|cover    |293         |[size=39]      |#9:131        |#9:8       |[size=46]
3   |#9:12|song|CASEY JONES                    |original |312         |[size=47]      |#9:93         |#9:8       |[size=33]
4   |#9:13|song|DEAL                           |original |423         |[size=80]      |#9:93         |#9:8       |[size=65]
5   |#9:17|song|STELLA BLUE                    |original |328         |[size=31]      |#9:93         |#9:8       |[size=46]
6   |#9:21|song|COLD RAIN AND SNOW             |cover    |241         |[size=56]      |#9:131        |#9:8       |[size=59]
7   |#9:22|song|UNCLE JOHNS BAND               |original |332         |[size=49]      |#9:93         |#9:8       |[size=60]
8   |#9:28|song|MISSISSIPPI HALF-STEP          |original |234         |[size=7]       |#9:93         |#9:8       |[size=7]
9   |#9:29|song|HERE COMES SUNSHINE            |original |65          |[size=34]      |#9:93         |#9:8       |[size=32]
10  |#9:30|song|I FOUGHT THE LAW               |cover    |36          |[size=9]       |#9:405        |#9:8       |[size=9]
11  |#9:32|song|WEREWOLVES OF LONDON           |cover    |12          |[size=6]       |#9:403        |#9:8       |[size=7]
12  |#9:34|song|ATTICS OF MY LIFE              |original |48          |[size=15]      |#9:93         |#9:8       |[size=19]
13  |#9:36|song|FOOLISH HEART                  |original |87          |[size=39]      |#9:93         |#9:8       |[size=37]
14  |#9:43|song|SHAKEDOWN STREET               |original |163         |[size=50]      |#9:93         |#9:8       |[size=54]
15  |#9:44|song|LIBERTY                        |original |56          |[size=16]      |#9:93         |#9:8       |[size=11]
16  |#9:45|song|US BLUES                       |original |323         |[size=4]       |#9:93         |#9:8       |[size=5]
17  |#9:48|song|BIRDSONG                       |original |296         |[size=29]      |#9:93         |#9:8       |[size=22]
18  |#9:49|song|IKO IKO                        |cover    |185         |[size=58]      |#9:131        |#9:8       |[size=66]
19  |#9:51|song|KNOCKING ON HEAVENS DOOR       |cover    |76          |[size=20]      |#9:308        |#9:8       |[size=12]
----+-----+----+-------------------------------+---------+------------+---------------+--------------+-----------+--------------
LIMIT EXCEEDED: resultset contains more items not displayed (limit=20)

20 item(s) found. Query executed in 0.065 sec(s).
select expand(set(in('sung_by'))) from #9:8

上記は一緒の結果になりますが一旦置いておきましょう

次はガルシアが歌った歌の作者を取得してみます。

select * from (traverse out_written_by from (select * from ( traverse in_sung_by from ( select * from V where @rid=#9:8 ) ) where type='song')) where type='artist'
orientdb {GratefulDeadConcerts}> select * from (traverse out_written_by from (select * from ( traverse in_sung_by from ( select * from V where @rid=#9:8 ) ) where type='song')) where type='artist'

----+------+------+-------------+----------+-----------------------
#   |@RID  |type  |in_written_by|in_sung_by|name
----+------+------+-------------+----------+-----------------------
0   |#9:7  |artist|[size=9]     |[size=7]  |Bo_Diddley
1   |#9:93 |artist|[size=96]    |[size=3]  |Hunter
2   |#9:131|artist|[size=39]    |null      |Traditional
3   |#9:405|artist|#9:30        |null      |Sonny_Curtis
4   |#9:403|artist|#9:32        |null      |Warren_Zevon
5   |#9:308|artist|[size=38]    |[size=22] |Bob_Dylan
6   |#9:327|artist|[size=12]    |null      |Lennon_McCartney
7   |#9:352|artist|#9:83        |null      |Bonnie_Dobson
8   |#9:414|artist|#9:161       |null      |Hank_Williams
9   |#9:265|artist|[size=3]     |null      |Noah_Lewis
10  |#9:344|artist|[size=3]     |null      |Merle_Haggard
11  |#9:399|artist|#9:215       |null      |Elizabeth_Cotten
12  |#9:364|artist|#9:226       |null      |Paul_McCartney
13  |#9:8  |artist|[size=4]     |[size=146]|Garcia
14  |#9:417|artist|#9:249       |null      |Leroy_Carr_Frank_Stokes
15  |#9:379|artist|#9:250       |null      |Rodney_Crowell
16  |#9:390|artist|[size=2]     |null      |George_Harrison
17  |#9:245|artist|[size=5]     |null      |Chuck_Berry
18  |#9:411|artist|#9:300       |null      |Bob_Marley
19  |#9:451|artist|[size=2]     |null      |Leadbelly
----+------+------+-------------+----------+-----------------------
LIMIT EXCEEDED: resultset contains more items not displayed (limit=20)

20 item(s) found. Query executed in 0.044 sec(s).

3. OrientDB Studio

OrientDBにはデフォルトでOrient StudioなるWebアプリケーションが用意されています。Communityエディションでもつかえます。
OrientDBが起動している状態であればそのブラウザからアクセスすることが可能です。こちらからデータベースの情報やSQLの実行も可能です。
デフォルトは2480ポートで稼働するようになっていますので ‘http://%稼働中のサーバーのURL%:2480/’ にアクセスしてみてください。
今回は稼働しているの同じマシンでテストしていますので、
http://localhost:2480/
でアクセスしてみます。

以下の画面が立ち上がります。
SnapCrab_Desktop_2014-8-20_19-31-50_No-00

ログインするとこちらの画面に遷移します(もしくはメニューからbrawseをクリックしてください)。

SnapCrab_Desktop_2014-8-20_20-11-28_No-00
こちらからSQL コマンドの実行が可能です。

select * from V where type = 'song’ and performances > 10

を実行してみます。
SnapCrab_Desktop_2014-8-20_20-12-28_No-00
それではコンソールで最後に実行したトラバースを実行してみます。

select * from (traverse out_written_by from (select * from ( traverse in_sung_by from ( select * from V where @rid=#9:8 ) ) where type='song')) where type='artist'

SnapCrab_Desktop_2014-8-20_19-34-11_No-00