-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.html
executable file
·1217 lines (1083 loc) · 31.5 KB
/
sql.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<html>
<head>
<title>SQL Queries for Mbench</title>
</head>
<body>
<H1>SQL Queries for Mbench</H1>
<table><tr bgcolor="aqua"><td>
The SQL schema is as follows:
</td></tr></table>
<pre>
CREATE TABLE eNest(eNest_ID integer not null,
eNest_parentID integer not null,
eNest_parentCODE varchar(50),
eNest_childOrder integer not null,
eNest_aUnique1 integer not null,
eNest_aUnique2 integer not null,
eNest_aLevel integer not null,
eNest_aFour integer not null,
eNest_aSixteen integer not null,
eNest_aSixtyFour integer not null,
eNest_aString varchar(40),
eNest_val varchar(600),
primary key (eNest_ID));
CREATE TABLE eOccasional(eOccasional_ID integer not null,
eOccasional_parentID integer not null,
eOccasional_parentCODE varchar(50),
eOccasional_childOrder integer not null,
eOccasional_aRef integer not null,
eOccasional_val varchar(550),
primary key (eOccasional_ID));
</pre>
<!-- QR1 -->
<table><tr bgcolor="aqua"><td>
-- QR1: Select all elements with aSixtyFour = 2 (Return only the element in question)
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest
where eNest_aSixtyFour = 2;
</pre>
<br/>
<pre>
<!-- QR2 -->
<table><tr bgcolor="aqua"><td>
-- QR2: Select all elements with aSixtyFour = 2 (Return the element and all
-- its immediate children)
</td></tr></table>
<pre>
create table tmp2_qr2(aUnique1ID integer, ID integer);
create table tmp1_qr2(parentID integer, childID integer);
-- contains all elements with aSixtyFour = 2
delete from tmp2_qr2;
insert into tmp2_qr2
select eNest_aUnique1, eNest_ID
from eNest
where eNest_aSixtyFour = 2;
-- contains elements with aSixtyFour = 2 that have eNest children
delete from tmp1_qr2;
insert into tmp1_qr2
select p.aUnique1ID as parentID, c.eNest_aUnique1 as childID
from tmp2_qr2 p
left outer join
eNest c
on p.ID = c.eNest_parentID;
insert into tmp1_qr2
select p.aUnique1ID as parentID, c.eOccasional_aRef as childID
from tmp2_qr2 p,
eOccasional c
where p.ID = c.eOccasional_parentID;
select parentID, count(childID)
from tmp1_qr2
group by parentID;
</pre>
<br/>
<!-- QR3 -->
<table><tr bgcolor="aqua"><td>
-- QR3: Select all elements with aSixtyFour = 2 (Return the entire subtree)
</td></tr></table>
<pre>
drop view tmp1_qr3;
create view tmp1_qr3 as
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'descendant' to
-- store the descendants of 'eNest' nodes with
-- 'aSixtyFour' = 2
select rootID, ID
from descendant;
select r.eNest_aUnique1, count(d.eNest_aUnique1)
from eNest r, eNest d, tmp1_qr3
where r.eNest_ID = tmp1_qr3.rootID
and d.eNest_ID = tmp1_qr3.ID
group by r.eNest_aUnique1;
</pre>
<!-- QR4 -->
<table><tr bgcolor="aqua"><td>
-- QR4: Select all elements with aSixtyFour = 2 and selected descendants
with aFour = 1
</td></tr></table>
<pre>
create table tmp2_qr4(aUnique1 integer, numD integer);
create table tmp3_qr4(aUnique1 integer, numD integer);
drop view tmp1_qr4;
create view tmp1_qr4 as
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'descendant' to
-- store the descendants with 'aFour' = 1 with
-- 'eNest' nodes with 'aSixtyFour' = 2
select rootID, ID
from descendant;
delete from tmp2_qr4;
insert into tmp2_qr4
select r.eNest_aUnique1, count(d.eNest_aUnique1)
from eNest r, eNest d, tmp1_qr4
where r.eNest_ID = tmp1_qr4.rootID
and d.eNest_ID = tmp1_qr4.ID
and d.eNest_aFour = 1
group by r.eNest_aUnique1;
delete from tmp3_qr4;
insert into tmp3_qr4
select eNest_aUnique1,0
from eNest
where eNest_aSixtyFour = 2;
select t1.aUnique1, t2.numD
from tmp3_qr4 t1
left outer join
tmp2_qr4 t2
on t1.aUnique1 = t2.aUnique1;
</pre>
<!-- QS1 -->
<table><tr bgcolor="aqua"><td>
-- QS1: Select elements with aString = 'Sing a song of oneB4'
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest e
where eNest_aString = 'Sing a song of oneB1';
</pre>
<!-- QS2 -->
<table><tr bgcolor="aqua"><td>
-- QS2: Select elements with aString = 'Sing a song of oneB1'
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest e
where eNest_aString = 'Sing a song of oneB4';
</pre>
<!-- QS3 -->
<table><tr bgcolor="aqua"><td>
-- QS3: Select elements with aLevel = 10
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest e
where eNest_aLevel = 10;
</pre>
<!-- QS4 -->
<table><tr bgcolor="aqua"><td>
-- QS4: Select elements with aLevel = 13
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest e
where eNest_aLevel = 13;
</pre>
<!-- QS5 -->
<table><tr bgcolor="aqua"><td>
-- QS5: Select nodes that have aSixtyFour between 5 and 8.
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest
where eNest_aSixtyFour between 5 and 8;
</pre>
<!-- QS6 -->
<table><tr bgcolor="aqua"><td>
-- QS6: Select nodes with aLevel = a13 and have the returned
nodes sorted by aSixtyFour attribute.
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest
where eNest_aLevel = 13
order by eNest_aSixtyFour;
</pre>
<!-- QS7 -->
<table><tr bgcolor="aqua"><td>
-- QS7: Select nodes with aSixteen = 1 and aFour = 1.
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest e
where eNest_aFour = 1
and eNest_aSixteen = 1;
</pre>
<!-- QS8 -->
<table><tr bgcolor="aqua"><td>
-- QS8: Selection based on the element name, eOccasional
</td></tr></table>
<pre>
select eOccasional_aRef
from eOccasional e;
</pre>
<!-- QS9 -->
<table><tr bgcolor="aqua"><td>
-- QS9: Select the second child of every node with aLevel = 7
</td></tr></table>
<pre>
select eChild.eNest_aUnique1
from eNest eParent, eNest eChild
where eParent.eNest_aLevel = 7
and eChild.eNest_childOrder = 2
and eParent.eNest_ID = eChild.eNest_parentID
and eChild.eNest_parentCODE = 'eNest';
</pre>
<!-- QS10 -->
<table><tr bgcolor="aqua"><td>
-- QS10: Select the second child of every node with aLevel = 9
</td></tr></table>
<pre>
select eChild.eNest_aUnique1
from eNest eParent, eNest eChild
where eParent.eNest_aLevel = 9
and eChild.eNest_childOrder = 2
and eParent.eNest_ID = eChild.eNest_parentID
and eChild.eNest_parentCODE = 'eNest';
</pre>
<!-- QS11 -->
<table><tr bgcolor="aqua"><td>
-- QS11: Get 'eOccasional' nodes that have element content
-- contains "oneB4"
</td></tr></table>
<pre>
select eOccasional_aRef
from eOccasional e
where eOccasional_val like '%oneB4%';
</pre>
<!-- QS12 -->
<table><tr bgcolor="aqua"><td>
-- QS12: Get nodes that have element content contains "oneB4"
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest e
where eNest_val like '%oneB4%';
</pre>
<!-- QS13 -->
<table><tr bgcolor="aqua"><td>
-- QS13: select all nodes with element content that the distance between
<br/>
-- keyword "oneB5" and the keyword "twenty" is not more than four
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest
where eNest_val like '%oneB5%'
and isRightDist(eNest_val, 'twenty ', 'oneB5',4) = 1;
</pre>
<!-- QS14 -->
<table><tr bgcolor="aqua"><td>
-- QS14: select all nodes with element content that the distance between
<br/>
-- keyword "oneB2" and the keyword "twenty" is not more than four
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest
where eNest_val like '%oneB2%'
and isRightDist(eNest_val, 'twenty ', 'oneB2',4) = 1;
</pre>
<!-- QS15 -->
<table><tr bgcolor="aqua"><td>
-- QS15: Local ordering. Select the second element with aFour = 1 below
<br/>
-- each element with aFour = 1 if that second element also has aFour = 1
</td></tr></table>
<pre>
select eChild.eNest_aUnique1
from eNest eParent, eNest eChild
where eParent.eNest_aFour = 1
and eChild.eNest_aFour = 1
and eParent.eNest_ID = eChild.eNest_parentID
and eChild.eNest_parentCODE = 'eNest'
and eChild.eNest_childOrder = 2;
</pre>
<!-- QS16 -->
<table><tr bgcolor="aqua"><td>
-- QS16: Global ordering. Select the second element with aFour = 1 below
<br/>
-- any element with aSixtyFour = 1
<br/>
</td></tr></table>
<pre>
select eChild.eNest_aUnique1
from eNest eChild,
(select eParent.eNest_ID
from eNest eParent
where eParent.eNest_aSixtyFour = 1) as tmp(eParentID)
where eChild.eNest_aFour = 1
and eChild.eNest_childOrder = 2
and eChild.eNest_parentID = eParentID
and eChild.eNest_parentCODE = 'eNest'
fetch first 1 rows only;
</pre>
<!-- QS17 -->
<table><tr bgcolor="aqua"><td>
-- QS17: Reverse ordering. Among the children with aSixteen = 1 of the
<br/>
-- parent element with aLevel = 13, select the last child<br/>
</td></tr></table>
<pre>
drop view tmp1_qs17;
create view tmp1_qs17(parentID, ID, cOrder) as
select eChild.eNest_parentID, eChild.eNest_ID, eChild.eNest_childOrder
from eNest eParent, eNest eChild
where eParent.eNest_aLevel = 13
and eChild.eNest_aSixteen = 1
and eChild.eNest_parentID = eParent.eNest_ID
and eChild.eNest_parentCODE = 'eNest';
drop view tmp3_qs17;
create view tmp3_qs17(parentID, ID) as
select t1.parentID, ID
from tmp1_qs17 t1,
(select parentID, max(cOrder)
from tmp1_qs17 t2
group by t2.parentID) as tmp2_qs17(parentID, order)
where t1.parentID = tmp2_qs17.parentID
and t1.cOrder = tmp2_qs17.order;
select eNest_aUnique1
from eNest c, tmp3_qs17
where c.eNest_ID = tmp3_qs17.ID;
select eParent.eNest_aUnique1
from eNest eParent, eNest eChild
where eParent.eNest_aFour = 1
and eChild.eNest_aFour = 1
and eParent.eNest_ID = eChild.eNest_parentID
and eChild.eNest_parentCODE = 'eNest'
and eChild.eNest_childOrder = 2;
</pre>
<!-- QS18 -->
<table><tr bgcolor="aqua"><td>
-- QS18: Moderate selectivity of both parent and child. Select nodes with
<br/>
-- aLevel = 13 that have a child with attribute aSixteen = 3
</td></tr></table>
<pre>
select eParent.eNest_aUnique1
from eNest eParent, eNest eChild
where eParent.eNest_aLevel = 13
and eChild.eNest_aSixteen = 3
and eParent.eNest_ID = eChild.eNest_parentID
and eChild.eNest_parentCODE = 'eNest';
</pre>
<!-- QS19 -->
<table><tr bgcolor="aqua"><td>
-- QS19: High selectivity of parent and low selectivity of child.
<br/>
-- Select nodes with aLevel = 15 that have a child with
<br/>
-- attribute aSixtyFour = 3
</td></tr></table>
<pre>
select eParent.eNest_aUnique1
from eNest eParent, eNest eChild
where eParent.eNest_aLevel = 15
and eChild.eNest_aSixtyFour = 3
and eParent.eNest_ID = eChild.eNest_parentID
and eChild.eNest_parentCODE = 'eNest';
s
</pre>
<!-- QS20 -->
<table><tr bgcolor="aqua"><td>
-- QS20: Reverse ordering. Select the last element with aSixteen = 1
<br/>
-- below each element with aLevel = 13
<br/>
-- 1) find the ID of element that has the last order
<br/>
-- 2) get the element that has the matching ID found in 1) and
<br/>
-- that has aSixteen = 1
</td></tr></table>
<pre>
select eParent.eNest_aUnique1
from eNest eParent, eNest eChild
where eParent.eNest_aLevel = 11
and eChild.eNest_aFour = 3
and eParent.eNest_ID = eChild.eNest_parentID
and eChild.eNest_parentCODE = 'eNest';
</pre>
<!-- QS21 -->
<table><tr bgcolor="aqua"><td>
-- QS21: Moderate selectivity of both ancestor and descendant. Select
<br/>
-- nodes with aLevel = 13 that have a descendant with aSixteen = 3
</td></tr></table>
<pre>
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'ancestor' to
-- store the ancestor of 'eNest' nodes
-- with 'aSixteen' = 3
select distinct eNest_aUnique1
from eNest, ancestor
where eNest.eNest_ID = ancestor.ID
and eNest.eNest_aLevel = 13;
</pre>
<!-- QS22 -->
<table><tr bgcolor="aqua"><td>
-- QS22: High selectivity of ancestor and low selectivity of descendant
<br/>
-- Select nodes with aLevel = 15 that have a descendant with
<br/>
-- aSixtyFour = 3
</td></tr></table>
<pre>
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'ancestor' to
-- store the ancestor of 'eNest' nodes
-- with 'aSixteen' = 3
select distinct eNest_aUnique1
from eNest, ancestor
where eNest.eNest_ID = ancestor.ID
and eNest.eNest_aLevel = 15;
</pre>
<!-- QS23 -->
<table><tr bgcolor="aqua"><td>
-- QS23: Low selectivity of ancestor and high selectivity of descendant
<br/>
-- Select nodes with aLevel = 11 that have a descendant with
<br/>
-- aFour = 3
</td></tr></table>
<pre>
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'descendant' to
-- store the descendants of 'eNest' nodes
-- with 'aLevel' = 11
select distinct e1.eNest_aUnique1
from descendant d, eNest e1, eNest e2
where d.rootID = e1.eNest_ID
and e1.eNest_aLevel = 11
and d.ID = e2.eNest_ID
and e2.eNest_aFour = 3;
</pre>
<!-- QS24 -->
<table><tr bgcolor="aqua"><td>
-- QS24: Moderate selectivity of both ancestor and descendant.
<br/>
-- Select nodes with aSixteen = 3 that have a descendant with
<br/>
-- aSixteen = 5
</td></tr></table>
<pre>
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'ancestor' to
-- store the ancestor of 'eNest' nodes with 'aSixteen' = 5
select distinct eNest_aUnique1
from eNest, ancestor
where eNest.eNest_ID = ancestor.ID
and eNest.eNest_aSixteen = 3;
</pre>
<!-- QS25 -->
<table><tr bgcolor="aqua"><td>
-- QS25: High selectivity of ancestor and low selectivity of descendant
<br/>
-- Select nodes with aFour = 3 that have a descendant with
<br/>
-- aSixtyFour= 3
</td></tr></table>
<pre>
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'tmp1_qs25' to
-- store the ancestor of 'eNest' nodes
-- with 'aSixtyFour' = 3
select distinct eNest_aUnique1
from eNest, ancestor
where eNest.eNest_ID = ancestor.ID
and eNest.eNest_aFour = 3;
</pre>
<!-- QS26 -->
<table><tr bgcolor="aqua"><td>
-- QS26: Low selectivity of ancestor and high selectivity of descendant
<br/>
-- Select nodes with aSixtyFour = 9 that have a descendant with
<br/>
-- aFour = 3
</td></tr></table>
<pre>
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'descendant' to
-- store the descendants of 'eNest' nodes
-- with 'aFour' = 3
select distinct eNest_aUnique1
from eNest e1, eNest e2, descendant d
where d.rootID = e1.eNest_ID
and e1.eNest_aSixtyFour = 9
and d.ID = e2.eNest_ID
and eNest.eNest_aFour = 3;
</pre>
<!-- QS27 -->
<table><tr bgcolor="aqua"><td>
-- QS27: Low selectivity of ancestor and high selectivity of descendant
<br/>
-- Select nodes with aSixtyFour = 9 that have a descendant with
<br/>
-- aFour = 3. Return a pair of ancestor and descendant nodes.
</td></tr></table>
<pre>
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'descendant' to
-- store the ancestor of 'eNest' nodes
-- with 'aFour' = 3
select distinct e1.eNest_aUnique1, e2.eNest_aUnique1
from eNest e1, eNest e2, descendant d
where d.rootID = e1.eNest_ID
and e1.eNest_aSixtyFour = 9
and d.ID = e2.eNest_ID
and eNest.eNest_aFour = 3;
</pre>
<!-- QS28 -->
<table><tr bgcolor="aqua"><td>
-- QS28: One chain query with three parent-child joins with the selectivity
<br/>
-- pattern: high-low-low-high, to test the choice of join order in
<br/>
-- evaluating a complex query. To achieve the desired selectivities,
<br/>
-- we use the following predicates: aFour = 3, aSixteen = 3,
<br/>
-- aSixteen = 5, and aLevel = 16
</td></tr></table>
<pre>
select distinct node1.eNest_aUnique1
from eNest node1, eNest node2, eNest node3, eNest node4
where node1.eNest_aFour = 3
and node2.eNest_aSixteen = 3
and node3.eNest_aSixteen = 5
and node4.eNest_aLevel = 16
and node2.eNest_parentID = node1.eNest_ID
and node2.eNest_parentCODE = 'eNest'
and node3.eNest_parentID = node2.eNest_ID
and node3.eNest_parentCODE = 'eNest'
and node4.eNest_parentID = node3.eNest_ID
and node4.eNest_parentCODE = 'eNest';
</pre>
<!-- QS29 -->
<table><tr bgcolor="aqua"><td>
-- QS29: One twig query with two parent child selection, low seletivity of
<br/>
-- parent aLevel = 11, high selectivity of left child aFour = 3,
<br/>
-- and low selectivity of right child aSixtyFour = 3
</td></tr></table>
<pre>
select distinct eParent.eNest_aUnique1
from eNest eParent, eNest eChild1, eNest eChild2
where eParent.eNest_aLevel = 11
and eChild1.eNest_aFour = 3
and eChild2.eNest_aSixtyFour = 3
and eChild1.eNest_parentID = eParent.eNest_ID
and eChild1.eNest_parentCODE = 'eNest'
and eChild2.eNest_parentID = eParent.eNest_ID
and eChild2.eNest_parentCODE = 'eNest'
and eChild1.eNest_ID <> eChild2.eNest_ID;
</pre>
<!-- QS30 -->
<table><tr bgcolor="aqua"><td>
-- QS30: One twig query with two parent child selection, low seletivity of
<br/>
-- parent aLevel = 11, high selectivity of left child aFour = 3,
<br/>
-- and low selectivity of right child aSixtyFour = 3
</td></tr></table>
<pre>
select distinct eParent.eNest_aUnique1
from eNest eParent, eNest eChild1, eNest eChild2
where eParent.eNest_aLevel = 11
and eChild1.eNest_aFour = 3
and eChild2.eNest_aSixtyFour = 3
and eChild1.eNest_parentID = eParent.eNest_ID
and eChild1.eNest_parentCODE = 'eNest'
and eChild2.eNest_parentID = eParent.eNest_ID
and eChild2.eNest_parentCODE = 'eNest'
and eChild1.eNest_ID <> eChild2.eNest_ID;
</pre>
<!-- QS31 -->
<table><tr bgcolor="aqua"><td>
-- QS31: One chain query with three ancestor-descendant joins with the selectivity
<br/>
-- pattern: high-low-low-high, to test the choice of join order in
<br/>
-- evaluating a complex query. To achieve the desired selectivities,
<br/>
-- we use the following predicates: aFour = 3, aSixteen = 3,
<br/>
-- aSixteen = 5, and aLevel = 16
</td></tr></table>
<pre>
create table tmp2_qs31(aID integer);
create table tmp3_qs31(aID integer);
create table tmp4_qs31(aID integer);
create table tmp5_qs31(ID integer);
drop view tmp1_qs31
create view tmp1_qs31(aID) as
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'ancestor1' to
-- store the ancestors of 'eNest' nodes
-- with 'aLevel' = 16
select distinct ID
from ancestor1;
delete from tmp2_qs31;
insert into tmp2_qs31
select a.eNest_ID as aID
from eNest a, tmp1_qs31
where a.eNest_ID = tmp1_qs31.ID
and a.eNest_aSixteen = 5;
delete from tmp3_qs31;
insert into tmp3_qs31
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'tmp2_qs31' to
-- store the ancestors of 'eNest' nodes
-- with 'aLevel' = 16 that have ancestor nodes
-- with 'aSixteen' = 5 in 'tmp3_qs31'
select distinct ID
from ancestor2;
delete from tmp4_qs31;
insert into tmp4_qs31
select a.eNest_ID as aID
from eNest a, tmp3_qs31
where a.eNest_ID = tmp3_qs31.ID
and a.eNest_aSixteen = 3;
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'tmp4_qs31' to
-- store the ancestors of 'eNest' nodes with
-- 'aLevel' = 16 that have ancestor nodes with
-- 'aSixteen' = 5, and that have ancestor nodes with
-- 'aSixteen' = 3 in 'tmp5_qs31'
select distinct a.eNest_aUnique1
from eNest a, tmp5_qs31
where a.eNest_ID = tmp5_qs31.ID
and a.eNest_aFour = 3;
</pre>
<!-- QS32 -->
<table><tr bgcolor="aqua"><td>
-- QS32: One twig query with two ancestor descendant selection, low selectivity
<br/>
-- of ancestor aLevel = 11, high selectivity of one descendant aFour = 3,
<br/>
-- and low selectivity of another descendant aSixtyFour = 3
</td></tr></table>
<pre>
create table tmp1_qs32(aUnique1 integer);
create table tmp2_qs32(aUnique1 integer);
delete from tmp1_qs32;
insert into tmp1_qs32
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'tmp1_qs32' to
-- store the ancestors of 'eNest' nodes
-- with 'aSixtyFour' = 3
select distinct eNest_aUnique1
from ancestor, eNest
where eNest_aLevel = 11
and eNest_ID = ID;
delete from tmp2_qs32;
insert into tmp2_qs32
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'tmp2_qs32' to
-- store the ancestors of 'eNest' nodes
-- with 'aFour' = 3
select distinct eNest_aUnique1
from ancestor, eNest
where eNest_aLevel = 11
and eNest_ID = ID;
select tmp1_qs32.aUnique1
from tmp1_qs32, tmp2_qs32
where tmp1_qs32.aUnique1 = tmp2_qs32.aUnique1;
</pre>
<!-- QS33 -->
<table><tr bgcolor="aqua"><td>
-- QS33: One twig query with two ancestor descendant selection, low selectivity
<br/>
-- of ancestor aFour = 1, low selectivity of one descendant aLevel = 11,
<br/>
-- and low selectivity of another descendant aSixtyFour = 3
</td></tr></table>
<pre>
drop view tmp1_qs33;
create view tmp1_qs33(ID, aUnique1) as
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'ancestor' to
-- store the ancestors of 'eNest' nodes
-- with 'aLevel' = 11
select distinct ID, eNest_aUnique1
from ancestor, eNest
where eNest_aFour = 1
and eNest_ID = ID;
drop view tmp2_qs33;
create view tmp2_qs33(ID, aUnique1) as
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'ancestor' to
-- store the ancestors of 'eNest' nodes
-- with 'aSixtyFour' = 3
select distinct ID, eNest_aUnique1
from ancestor, eNest
where eNest_aFour = 1
and eNest_ID = ID;
select tmp1_qs33.aUnique1
from tmp1_qs33, tmp2_qs33
where tmp1_qs33.ID = tmp2_qs33.ID;
</pre>
<!-- QS34 -->
<table><tr bgcolor="aqua"><td>
-- QS34: One twig query with two ancestor descendant selection, low selectivity
<br/>
-- of ancestor aFour = 1, low selectivity of a child with aLevel = 11,
<br/>
-- and low selectivity of another descendant aSixtyFour = 3
</td></tr></table>
<pre>
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'ancestor' to
-- store the ancestors of 'eNest' nodes
-- with 'aSixtyFour' = 3
select distinct a.eNest_aUnique1
from eNest a, ancestor, eNest c
where a.eNest_ID = ancestor.ID
and c.eNest_parentID = a.eNest_ID
and c.eNest_parentCODE = 'eNest'
and c.eNest_aLevel = 11
and a.eNest_aFour = 1;
</pre>
<!-- QS35 -->
<table><tr bgcolor="aqua"><td>
-- QS35: Missing Elements. Find all BaseType elements that there is
<br/>
-- no OccasionalType elements below them.
<br/>
-- 1) Find all BaseType elements that there is some OccasionalType
<br/>
-- elements below them.
<br/>
-- 2) Return elements that are not in 1)
</td></tr></table>
<pre>
create table tmp1(ID integer, hasOccasional integer);
delete from tmp1;
insert into tmp1;
-- vendor specific call for recursive query removed
-- recursive join 'eNest' table and 'subeNest' to
-- store 'eNest' nodes that have 'eOccasional'
-- as descendants
select distinct ID, hasOccasional
from subeNest;
drop view tmp2;
create view tmp2(aUnique1, hasOccasional) as
select eNest_aUnique1, t.hasOccasional
from eNest c
left outer join
tmp t
on t.ID = c.eNest_ID;
select aUnique1 from tmp2
where hasOccasional is null;
</pre>
<!-- QJ1 -->
<table><tr bgcolor="aqua"><td>
-- QJ1: Low selectivity join: select nodes with aSixtyFour = 2 and join
<br/>
-- with themselves based on the equality of aUnique1 attribute
</td></tr></table>
<pre>
select e1.eNest_aUnique1, e2.eNest_aUnique1
from eNest e1, eNest e2
where e1.eNest_aSixtyFour = 2
and e1.eNest_aSixtyFour = e2.eNest_aSixtyFour
and e1.eNest_aUnique1 = e2.eNest_aUnique1;
</pre>
<!-- QJ2 -->
<table><tr bgcolor="aqua"><td>
-- QJ2: Low selectivity join: select nodes with aSixteen = 2 and join
<br/>
-- with themselves based on the equality of aUnique1 attribute
</td></tr></table>
<pre>
select e1.eNest_aUnique1, e2.eNest_aUnique1
from eNest e1, eNest e2
where e1.eNest_aSixteen = 2
and e1.eNest_aSixteen = e2.eNest_aSixteen
and e1.eNest_aUnique1 = e2.eNest_aUnique1;
</pre>
<!-- QJ3 -->
<table><tr bgcolor="aqua"><td>
-- QJ3: Low selectivity join: select all OccasionalType nodes that point to
<br/>
-- a node with aSixtyFour = 3
</td></tr></table>
<pre>
select eOccasional_aRef
from eOccasional, eNest
where eNest_aSixtyFour = 3
and eNest_aUnique1 = eOccasional_aRef;
</pre>
<!-- QJ4 -->
<table><tr bgcolor="aqua"><td>
-- QJ4: Low selectivity join: select all OccasionalType nodes that point to
<br/>
-- a node with aFour = 3
</td></tr></table>
<pre>
select eOccasional_aRef
from eOccasional, eNest
where eNest_aFour = 3
and eNest_aUnique1 = eOccasional_aRef;
</pre>
<!-- QA1 -->
<table><tr bgcolor="aqua"><td>
-- QA1: Over all nodes at level 15, compute the average value for the
<br/>
-- aSixtyFour attribute
</td></tr></table>
<pre>
select avg(eNest_aSixtyFour)
from eNest
where eNest_aLevel = 15;
</pre>
<!-- QA2 -->
<table><tr bgcolor="aqua"><td>
-- QA2: Over all nodes at all levels, compute the average value for the
<br/>
-- aSixtyFour attribute
</td></tr></table>
<pre>
select eNest_aLevel, avg(eNest_aSixtyFour)
from eNest
group by eNest_aLevel;
</pre>
<!-- QA3 -->
<table><tr bgcolor="aqua"><td>
-- QA3: Select elements that have at least two occurrences of keyword "oneB1"
<br/>
in their content
</td></tr></table>
<pre>
select eNest_aUnique1
from eNest
where eNest_val like '%oneB1%'
and isNumKeysGTE(eNest_val,'oneB1',2) = 1;
</pre>
<!-- QA4 -->
<table><tr bgcolor="aqua"><td>
-- QA3: Amongst the nodes at level 11, find the node(s) with the largest
<br/>
-- fanout.
<br/>
-- 1) find number of children of each node at level 11
<br/>
-- 2) find nodes that have the number of children equal to the
<br/>
-- the largest number of children.
</td></tr></table>
<pre>
CREATE TABLE tmp1_qa3(pID integer, cID integer);
CREATE TABLE tmp2_qa3(pID integer, numC integer);
delete from tmp1_qa3;
insert into tmp1_qa3;
select distinct p.eNest_ID, c.eNest_ID
from eNest p, eNest c
where c.eNest_parentID = p.eNest_ID
and p.eNest_aLevel = 11
union
select distinct p.eNest_ID, c.eOccasional_aRef
from eNest p, eOccasional c
where c.eOccasional_parentID = p.eNest_ID
and p.eNest_aLevel = 11;
delete from tmp2_qa3;
insert into tmp2_qa3
select pID, count(cID)
from tmp1_qa3
group by pID;
drop view tmp3_qa3;
create view tmp3_qa3(maxNumC) as
select distinct max(numC)
from tmp2_qa3;
select distinct eNest_aUnique1
from eNest, tmp2_qa3, tmp3_qa3
where eNest.eNest_ID = tmp2_qa3.pID
and numC = maxNumC;
</pre>
<!-- QA5 -->
<table><tr bgcolor="aqua"><td>
-- QA5: select elements that have at least two children that satisfy
<br/>
-- aFour = 1
</td></tr></table>
<pre>
select distinct eParent.eNest_aUnique1
from eNest eParent, eNest eChild1, eNest eChild2