Skip to content
Permalink
Browse files
[NO ISSUE][TEST] Add CH2 queries to optimizerts
- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Add CH2 queries to optimizer testsuite

Change-Id: Ic5d7362f4ca5a20f2591933de862a072a06c7b12
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/15183
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dmitry.lychagin@couchbase.com>
  • Loading branch information
vsarathy1 authored and Dmitry Lychagin committed Feb 16, 2022
1 parent f915206 commit 2a983d2420e6ca7e938e7393e12fc9488be925b0
Showing 44 changed files with 2,676 additions and 35 deletions.
@@ -18,49 +18,32 @@
*/

/*
* Test plan for CH2 Q8
* Test plan for CH2 Q1
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT
GET_YEAR(DATE(rn1coolis.o_entry_d)) AS l_year,
ROUND((SUM(CASE WHEN sun2.n_name = 'Germany' THEN rn1coolis.ol_amount ELSE 0 END) / SUM(rn1coolis.ol_amount)),2)
AS mkt_share
FROM (
SELECT rn1cooli.o_entry_d, rn1cooli.ol_amount, s.s_w_id, s.s_i_id
FROM stock s
JOIN (
SELECT o.o_entry_d, ol.ol_i_id, ol.ol_amount, ol.ol_supply_w_id
FROM orders o, o.o_orderline ol, item i
JOIN (
SELECT c.c_id,c.c_w_id, c.c_d_id
FROM customer c
JOIN (
SELECT n1.n_nationkey
FROM nation n1, region r
WHERE n1.n_regionkey = r.r_regionkey AND r.r_name = 'Europe'
) nr ON nr.n_nationkey = string_to_codepoint(c.c_state)[0]
) cnr ON cnr.c_id = o.o_c_id
AND cnr.c_w_id = o.o_w_id AND cnr.c_d_id = o.o_d_id AND i.i_data LIKE '%b'
AND i.i_id = ol.ol_i_id AND ol.ol_i_id < 1000
AND o.o_entry_d BETWEEN '2017-01-01 00:00:00.000000' AND '2018-12-31 00:00:00.000000'
) rn1cooli ON rn1cooli.ol_i_id = s.s_i_id AND rn1cooli.ol_supply_w_id = s.s_w_id
) rn1coolis
JOIN (
SELECT su.su_suppkey, n2.n_name
FROM supplier su, nation n2
WHERE su.su_nationkey = n2.n_nationkey
) sun2 ON rn1coolis.s_w_id * rn1coolis.s_i_id MOD 10000 = sun2.su_suppkey
GROUP BY get_year(date(rn1coolis.o_entry_d))
ORDER BY l_year;
SELECT ol.ol_number,
SUM(ol.ol_quantity) as sum_qty,
SUM(ol.ol_amount) as sum_amount,
AVG(ol.ol_quantity) as avg_qty,
AVG(ol.ol_amount) as avg_amount,
COUNT(*) as COUNT_order
FROM orders o, o.o_orderline ol
WHERE ol.ol_delivery_d > '2014-07-01 00:00:00'
GROUP BY ol.ol_number
ORDER BY ol.ol_number;
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Test plan for CH2 Q10
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT c.c_id, c.c_last, SUM(ol.ol_amount) as revenue, c.c_city, c.c_phone, n.n_name
FROM nation n, customer c, orders o, o.o_orderline ol
WHERE c.c_id = o.o_c_id
AND c.c_w_id = o.o_w_id
AND c.c_d_id = o.o_d_id
AND o.o_entry_d >= '2015-10-01 00:00:00.000000'
AND o.o_entry_d < '2016-01-01 00:00:00.000000'
AND n.n_nationkey = string_to_codepoint(c.c_state)[0]
GROUP BY c.c_id, c.c_last, c.c_city, c.c_phone, n.n_name
ORDER BY revenue DESC
LIMIT 20;
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Test plan for CH2 Q11
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT s.s_i_id, SUM(s.s_order_cnt) as ordercount
FROM nation n, supplier su, stock s
WHERE s.s_w_id * s.s_i_id MOD 10000 = su.su_suppkey
AND su.su_nationkey = n.n_nationkey
AND n.n_name = 'Germany'
GROUP BY s.s_i_id
HAVING SUM(s.s_order_cnt) >
(SELECT VALUE SUM(s1.s_order_cnt) * 0.00005
FROM nation n1, supplier su1, stock s1
WHERE s1.s_w_id * s1.s_i_id MOD 10000 = su1.su_suppkey
AND su1.su_nationkey = n1.n_nationkey
AND n1.n_name = 'Germany')[0]
ORDER BY ordercount DESC;
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Test plan for CH2 Q12
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT o.o_ol_cnt,
SUM (case WHEN o.o_carrier_id = 1 or o.o_carrier_id = 2
THEN 1 ELSE 0 END) AS high_line_COUNT,
SUM (case WHEN o.o_carrier_id <> 1 AND o.o_carrier_id <> 2
THEN 1 ELSE 0 END) AS low_line_COUNT
FROM orders o, o.o_orderline ol
WHERE o.o_entry_d <= ol.ol_delivery_d
AND ol.ol_delivery_d >= '2016-01-01 00:00:00.000000' AND ol.ol_delivery_d < '2017-01-01 00:00:00.000000'
GROUP BY o.o_ol_cnt
ORDER BY o.o_ol_cnt;
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Test plan for CH2 Q13
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT c_orders.c_count, COUNT(*) as custdist
FROM (SELECT c.c_id, COUNT(o.o_id) as c_count
FROM customer c LEFT OUTER JOIN orders o ON (
c.c_w_id = o.o_w_id
AND c.c_d_id = o.o_d_id
AND c.c_id = o.o_c_id
AND o.o_carrier_id > 8)
GROUP BY c.c_id) as c_orders
GROUP BY c_orders.c_count
ORDER BY custdist DESC, c_orders.c_count DESC;
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Test plan for CH2 Q14
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

SELECT 100.00 * SUM(CASE WHEN i.i_data LIKE 'pr%'
THEN ol.ol_amount ELSE 0 END) / (1+SUM(ol.ol_amount)) AS promo_revenue
FROM item i, orders o, o.o_orderline ol
WHERE ol.ol_i_id = i.i_id
AND ol.ol_delivery_d >= '2017-09-01 00:00:00.000000' AND ol.ol_delivery_d < '2017-10-01 00:00:00.000000';
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Test plan for CH2 Q15
*/

drop dataverse test if exists;
create dataverse test;
use test;

create dataset warehouse(id uuid not unknown) open type primary key `id` autogenerated;
create dataset district(id uuid not unknown) open type primary key `id` autogenerated;
create dataset customer(id uuid not unknown) open type primary key `id` autogenerated;
create dataset history(id uuid not unknown) open type primary key `id` autogenerated;
create dataset orders(id uuid not unknown) open type primary key `id` autogenerated;
create dataset neworder(id uuid not unknown) open type primary key `id` autogenerated;
create dataset supplier(id uuid not unknown) open type primary key `id` autogenerated;
create dataset item(id uuid not unknown) open type primary key `id` autogenerated;
create dataset stock(id uuid not unknown) open type primary key `id` autogenerated;
create dataset nation(id uuid not unknown) open type primary key `id` autogenerated;
create dataset region(id uuid not unknown) open type primary key `id` autogenerated;

WITH revenue AS (
SELECT s.s_w_id * s.s_i_id MOD 10000 as supplier_no, SUM(ol.ol_amount) AS total_rev
FROM stock s, orders o, o.o_orderline ol
WHERE ol.ol_i_id = s.s_i_id
AND ol.ol_supply_w_id = s.s_w_id
AND ol.ol_delivery_d >= '2018-01-01 00:00:00.000000' AND ol.ol_delivery_d < '2018-04-01 00:00:00.000000'
GROUP BY s.s_w_id * s.s_i_id MOD 10000)
SELECT su.su_suppkey, su.su_name, su.su_address, su.su_phone, r.total_revenue
FROM revenue r, supplier su
WHERE su.su_suppkey = r.supplier_no
AND r.total_revenue = (SELECT VALUE max(r1.total_revenue) FROM revenue r1)[0]
ORDER BY su.su_suppkey;

0 comments on commit 2a983d2

Please sign in to comment.