@@ -40,18 +40,27 @@ fn make_match_with_constraints() -> Clause {
4040 } ] )
4141}
4242
43- fn make_complex_query ( ) -> Vec < Clause > {
44- let match_clause = Clause :: Match ( vec ! [
43+ fn make_complex_query ( ) -> Clause {
44+ Clause :: Match ( vec ! [
4545 Pattern :: Entity {
4646 variable: "$p" . to_string( ) ,
4747 type_name: "person" . to_string( ) ,
48- constraints: vec![ Constraint :: Has {
49- attr_name: "name" . to_string( ) ,
50- value: Value :: Literal ( LiteralValue {
51- value: json!( "Alice" ) ,
52- value_type: "string" . to_string( ) ,
53- } ) ,
54- } ] ,
48+ constraints: vec![
49+ Constraint :: Has {
50+ attr_name: "name" . to_string( ) ,
51+ value: Value :: Literal ( LiteralValue {
52+ value: json!( "Alice" ) ,
53+ value_type: "string" . to_string( ) ,
54+ } ) ,
55+ } ,
56+ Constraint :: Has {
57+ attr_name: "age" . to_string( ) ,
58+ value: Value :: Literal ( LiteralValue {
59+ value: json!( 30 ) ,
60+ value_type: "long" . to_string( ) ,
61+ } ) ,
62+ } ,
63+ ] ,
5564 is_strict: false ,
5665 } ,
5766 Pattern :: Relation {
@@ -115,49 +124,40 @@ fn make_complex_query() -> Vec<Clause> {
115124 Pattern :: Entity {
116125 variable: "$d" . to_string( ) ,
117126 type_name: "department" . to_string( ) ,
118- constraints: vec![
119- Constraint :: Has {
120- attr_name: "budget" . to_string( ) ,
121- value: Value :: Literal ( LiteralValue {
122- value: json!( 100000.0 ) ,
123- value_type: "double" . to_string( ) ,
124- } ) ,
125- } ,
126- ] ,
127+ constraints: vec![ Constraint :: Has {
128+ attr_name: "budget" . to_string( ) ,
129+ value: Value :: Literal ( LiteralValue {
130+ value: json!( 100000.0 ) ,
131+ value_type: "double" . to_string( ) ,
132+ } ) ,
133+ } ] ,
127134 is_strict: false ,
128135 } ,
129- Pattern :: Iid {
130- variable: "$x" . to_string( ) ,
131- iid: "0xabcdef" . to_string( ) ,
132- } ,
133- Pattern :: Attribute {
134- variable: "$a" . to_string( ) ,
135- type_name: "salary" . to_string( ) ,
136- value: Some ( Value :: Literal ( LiteralValue {
137- value: json!( 75000 ) ,
138- value_type: "long" . to_string( ) ,
139- } ) ) ,
140- } ,
141- ] ) ;
142-
143- let fetch_clause = Clause :: Fetch ( vec ! [
144- FetchItem :: Attribute {
145- key: "name" . to_string( ) ,
146- var: "$p" . to_string( ) ,
147- attr_name: "name" . to_string( ) ,
148- } ,
149- FetchItem :: Attribute {
150- key: "email" . to_string( ) ,
151- var: "$p" . to_string( ) ,
152- attr_name: "email" . to_string( ) ,
136+ Pattern :: Entity {
137+ variable: "$mgr" . to_string( ) ,
138+ type_name: "manager" . to_string( ) ,
139+ constraints: vec![ Constraint :: Has {
140+ attr_name: "level" . to_string( ) ,
141+ value: Value :: Literal ( LiteralValue {
142+ value: json!( 3 ) ,
143+ value_type: "long" . to_string( ) ,
144+ } ) ,
145+ } ] ,
146+ is_strict: false ,
153147 } ,
154- FetchItem :: Wildcard {
155- key: "company" . to_string( ) ,
156- var: "$c" . to_string( ) ,
148+ Pattern :: Entity {
149+ variable: "$proj" . to_string( ) ,
150+ type_name: "project" . to_string( ) ,
151+ constraints: vec![ Constraint :: Has {
152+ attr_name: "deadline" . to_string( ) ,
153+ value: Value :: Literal ( LiteralValue {
154+ value: json!( "2025-12-31" ) ,
155+ value_type: "date" . to_string( ) ,
156+ } ) ,
157+ } ] ,
158+ is_strict: false ,
157159 } ,
158- ] ) ;
159-
160- vec ! [ match_clause, fetch_clause]
160+ ] )
161161}
162162
163163fn make_batch_clauses ( ) -> Vec < Clause > {
@@ -268,10 +268,10 @@ fn bench_compile_match_with_constraints(c: &mut Criterion) {
268268
269269fn bench_compile_complex_query ( c : & mut Criterion ) {
270270 let compiler = QueryCompiler :: new ( ) ;
271- let clauses = make_complex_query ( ) ;
271+ let clause = make_complex_query ( ) ;
272272
273273 c. bench_function ( "compile/complex_10_patterns" , |b| {
274- b. iter ( || compiler. compile ( black_box ( & clauses ) ) )
274+ b. iter ( || compiler. compile_clause ( black_box ( & clause ) ) )
275275 } ) ;
276276}
277277
@@ -305,12 +305,33 @@ fn bench_compile_reduce(c: &mut Criterion) {
305305 } ) ,
306306 } ,
307307 ReduceAssignment {
308- variable: "$total " . to_string( ) ,
308+ variable: "$total_salary " . to_string( ) ,
309309 expression: Value :: FunctionCall ( FunctionCallValue {
310310 function: "sum" . to_string( ) ,
311311 args: vec![ Value :: Variable ( "$salary" . to_string( ) ) ] ,
312312 } ) ,
313313 } ,
314+ ReduceAssignment {
315+ variable: "$max_age" . to_string( ) ,
316+ expression: Value :: FunctionCall ( FunctionCallValue {
317+ function: "max" . to_string( ) ,
318+ args: vec![ Value :: Variable ( "$age" . to_string( ) ) ] ,
319+ } ) ,
320+ } ,
321+ ReduceAssignment {
322+ variable: "$min_age" . to_string( ) ,
323+ expression: Value :: FunctionCall ( FunctionCallValue {
324+ function: "min" . to_string( ) ,
325+ args: vec![ Value :: Variable ( "$age" . to_string( ) ) ] ,
326+ } ) ,
327+ } ,
328+ ReduceAssignment {
329+ variable: "$avg_score" . to_string( ) ,
330+ expression: Value :: FunctionCall ( FunctionCallValue {
331+ function: "mean" . to_string( ) ,
332+ args: vec![ Value :: Variable ( "$score" . to_string( ) ) ] ,
333+ } ) ,
334+ } ,
314335 ] ,
315336 group_by : Some ( "$dept" . to_string ( ) ) ,
316337 } ;
@@ -991,6 +1012,18 @@ fn bench_compile_isa_constraint(c: &mut Criterion) {
9911012 ] ,
9921013 is_strict: false ,
9931014 } ,
1015+ Pattern :: Entity {
1016+ variable: "$v" . to_string( ) ,
1017+ type_name: "vehicle" . to_string( ) ,
1018+ constraints: vec![
1019+ Constraint :: Isa { type_name: "electric-vehicle" . to_string( ) , strict: false } ,
1020+ Constraint :: Has {
1021+ attr_name: "range" . to_string( ) ,
1022+ value: Value :: Literal ( LiteralValue { value: json!( 300 ) , value_type: "long" . to_string( ) } ) ,
1023+ } ,
1024+ ] ,
1025+ is_strict: false ,
1026+ } ,
9941027 ] ) ;
9951028 c. bench_function ( "compile/isa_constraint" , |b| {
9961029 b. iter ( || compiler. compile_clause ( black_box ( & clause) ) )
0 commit comments