5
5
use PhpBench \Benchmark \Iteration ;
6
6
use PHPCR \Benchmark \BaseBench ;
7
7
8
+ /**
9
+ * @group query
10
+ * @processIsolation iteration
11
+ */
8
12
class QueryBench extends BaseBench
9
13
{
10
- /**
11
- * @description Run a select query
12
- * @paramProvider provideQueryVariableProperties
13
- * @paramProvider provideNbNodes
14
- * @beforeMethod beforeCreateNodes
15
- * @iterations 1
16
- */
17
- public function benchQuery (Iteration $ iteration )
14
+ public function setUp ()
18
15
{
19
- $ query = $ this ->getQueryManager ()->createQuery ($ iteration ->getParameter ('query ' ), 'JCR-SQL2 ' );
20
- $ query ->execute ();
16
+ $ this ->loadDump ('large_website.xml ' );
21
17
}
22
18
23
19
/**
24
- * @description Run a select query and iterate
25
- * @paramProvider provideQueryVariableProperties
26
- * @paramProvider provideNbNodes
27
- * @beforeMethod beforeCreateNodes
28
- * @iterations 1
20
+ * @description No iterations
21
+ * @paramProvider provideQueries
22
+ * @iterations 5
23
+ * @group query_single_prop
29
24
*/
30
- public function benchQueryAndIterate (Iteration $ iteration )
25
+ public function benchQuery (Iteration $ iteration )
31
26
{
32
27
$ query = $ this ->getQueryManager ()->createQuery ($ iteration ->getParameter ('query ' ), 'JCR-SQL2 ' );
33
- $ result = $ query ->execute ();
34
-
35
- foreach ($ result ->getRows () as $ row ) {
36
- $ row ->getPath ();
37
- }
28
+ $ query ->execute ();
38
29
}
39
30
40
31
/**
41
- * @description Run a select query and get node for each result
42
- * @paramProvider provideQueryVariableProperties
43
- * @paramProvider provideNbNodes
44
- * @beforeMethod beforeCreateNodes
45
- * @iterations 2
32
+ * @description Retrive nodes for each row
33
+ * @paramProvider provideQueries
34
+ * @iterations 5
35
+ * @group query_single_prop
46
36
*/
47
- public function benchQueryAndIterateWithNode (Iteration $ iteration )
37
+ public function benchQueryWithNodes (Iteration $ iteration )
48
38
{
49
39
$ query = $ this ->getQueryManager ()->createQuery ($ iteration ->getParameter ('query ' ), 'JCR-SQL2 ' );
50
- $ result = $ query ->execute ();
51
-
52
- foreach ($ result ->getRows () as $ row ) {
53
- $ row ->getNode ()->getPath ();
54
- }
55
- }
56
-
57
- /**
58
- * @description Search by property
59
- * @paramProvider provideNbNodesWithSections
60
- * @beforeMethod beforeCreateNodes
61
- * @beforeMethod beforeAppendNode
62
- * @iterations 2
63
- */
64
- public function benchSearchByProperty ()
65
- {
66
- $ query = $ this ->getQueryManager ()->createQuery (
67
- 'SELECT * FROM [nt:unstructured] WHERE my_new_property = "foobar" '
68
- , 'JCR-SQL2 ' );
69
40
$ results = $ query ->execute ();
70
41
71
42
foreach ($ results as $ result ) {
@@ -74,17 +45,14 @@ public function benchSearchByProperty()
74
45
}
75
46
76
47
/**
77
- * @description Search by property in a subpath
78
- * @paramProvider provideNbNodesWithSections
79
- * @beforeMethod beforeCreateNodes
80
- * @beforeMethod beforeAppendNode
81
- * @iterations 2
48
+ * @description Iterate over rows and retrieve properties
49
+ * @paramProvider provideQueries
50
+ * @iterations 5
51
+ * @group query_single_prop
82
52
*/
83
- public function benchSearchByPropertyInSubpath ( )
53
+ public function benchQueryIterate ( Iteration $ iteration )
84
54
{
85
- $ query = $ this ->getQueryManager ()->createQuery (
86
- 'SELECT * FROM [nt:unstructured] WHERE my_new_property = "foobar" AND ISDESCENDANTNODE("/bench/section-0") '
87
- , 'JCR-SQL2 ' );
55
+ $ query = $ this ->getQueryManager ()->createQuery ($ iteration ->getParameter ('query ' ), 'JCR-SQL2 ' );
88
56
$ results = $ query ->execute ();
89
57
90
58
foreach ($ results as $ result ) {
@@ -93,115 +61,50 @@ public function benchSearchByPropertyInSubpath()
93
61
}
94
62
95
63
/**
96
- * @description Full text search within property
97
- * @paramProvider provideNbNodesWithSections
98
- * @beforeMethod beforeCreateNodes
99
- * @beforeMethod beforeAppendNode
100
- * @iterations 2
64
+ * @description Run a select query with variable amount of properties
65
+ * @paramProvider provideProperties
66
+ * @iterations 5
67
+ * @group query_variable_props
101
68
*/
102
- public function benchSearchPropertyFullText ( )
69
+ public function benchQueryIterateVariableProperties ( Iteration $ iteration )
103
70
{
104
- $ query = $ this ->getQueryManager ()->createQuery (
105
- 'SELECT * FROM [nt:unstructured] WHERE CONTAINS(my_new_property, "foobar") '
106
- , 'JCR-SQL2 ' );
107
- $ results = $ query ->execute ();
108
-
109
- foreach ($ results as $ result ) {
110
- $ result ->getNode ();
111
- }
112
- }
113
-
114
- public function beforeCreateNodes (Iteration $ iteration )
115
- {
116
- // do not recreate nodes in the same iteration set
117
- if ($ iteration ->getIndex () > 0 ) {
118
- $ this ->resetSession ();
119
- return ;
120
- }
71
+ $ props = $ iteration ->getParameter ('props ' );
72
+ $ query = $ this ->getQueryManager ()->createQuery (sprintf (
73
+ 'SELECT %s FROM [nt:unstructured] WHERE valves IS NOT NULL '
74
+ , implode (', ' , $ props )), 'JCR-SQL2 ' );
121
75
122
- $ this ->resetWorkspace ();
123
-
124
- // warmup the connection
125
- $ this ->getQueryManager ()->createQuery ('SELECT * FROM [nt:unstructured] ' , 'JCR-SQL2 ' )->execute ();
126
-
127
- $ this ->createNodes ($ this ->getRootNode (), $ iteration ->getParameter ('nb_nodes ' ), array (
128
- 'string ' => 'Hello ' ,
129
- 'number ' => 10 ,
130
- 'hello ' => 'goodbye ' ,
131
- 'goodbye ' => 'hello ' ,
132
- ), $ iteration ->getParameter ('sections ' ), 0 );
133
-
134
- $ this ->getSession ()->save ();
135
- }
76
+ $ results = $ query ->execute ();
136
77
137
- public function beforeAppendNode (Iteration $ iteration )
138
- {
139
- // do not recreate nodes in the same iteration set
140
- if ($ iteration ->getIndex () > 0 ) {
141
- return ;
78
+ foreach ($ results as $ row ) {
79
+ foreach ($ props as $ prop ) {
80
+ $ row ->getValue ($ prop );
81
+ }
142
82
}
143
-
144
- $ this ->createNodes ($ this ->getRootNode (), 1 , array (
145
- 'my_new_property ' => 'foobar ' ,
146
- ), 1 , 10000 );
147
-
148
- $ this ->getSession ()->save ();
149
83
}
150
84
151
- public function provideQueryVariableProperties ()
85
+ public function provideQueries ()
152
86
{
153
87
return array (
154
88
array (
155
- 'query ' => 'SELECT * FROM [nt:unstructured] ' ,
156
- ),
157
- array (
158
- 'query ' => 'SELECT string FROM [nt:unstructured] ' ,
159
- ),
160
- array (
161
- 'query ' => 'SELECT string, number FROM [nt:unstructured] ' ,
162
- ),
163
- array (
164
- 'query ' => 'SELECT string, number, hello, goodbye FROM [nt:unstructured] ' ,
165
- ),
166
- );
167
- }
168
-
169
- public function provideNbNodes ()
170
- {
171
- return array (
172
- array (
173
- 'nb_nodes ' => 1 ,
174
- 'sections ' => 1 ,
175
- ),
176
- array (
177
- 'nb_nodes ' => 10 ,
178
- 'sections ' => 1 ,
179
- ),
180
- array (
181
- 'nb_nodes ' => 100 ,
182
- 'sections ' => 1 ,
89
+ 'query ' => 'SELECT valves FROM [nt:unstructured] ' ,
183
90
),
184
91
);
185
92
}
186
93
187
- public function provideNbNodesWithSections ()
94
+ public function provideProperties ()
188
95
{
189
96
return array (
190
97
array (
191
- 'nb_nodes ' => 100 ,
192
- 'sections ' => 2 ,
98
+ 'props ' => array ('valves ' ),
193
99
),
194
100
array (
195
- 'nb_nodes ' => 1000 ,
196
- 'sections ' => 2 ,
101
+ 'props ' => array ('valves ' , 'thistles ' ),
197
102
),
198
103
array (
199
- 'nb_nodes ' => 100 ,
200
- 'sections ' => 4 ,
104
+ 'props ' => array ('valves ' , 'thistles ' , 'toppings ' , 'troikas ' ),
201
105
),
202
106
array (
203
- 'nb_nodes ' => 1000 ,
204
- 'sections ' => 4 ,
107
+ 'props ' => array ('valves ' , 'thistles ' , 'toppings ' , 'troikas ' , 'underrate ' , 'worksheets ' ),
205
108
),
206
109
);
207
110
}
0 commit comments