github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/cmd/benchdb/explaintest/r/tpch.result (about) 1 CREATE DATABASE IF NOT EXISTS TPCH; 2 USE TPCH; 3 CREATE TABLE IF NOT EXISTS nation ( N_NATIONKEY INTEGER NOT NULL, 4 N_NAME CHAR(25) NOT NULL, 5 N_REGIONKEY INTEGER NOT NULL, 6 N_COMMENT VARCHAR(152), 7 PRIMARY KEY (N_NATIONKEY)); 8 CREATE TABLE IF NOT EXISTS region ( R_REGIONKEY INTEGER NOT NULL, 9 R_NAME CHAR(25) NOT NULL, 10 R_COMMENT VARCHAR(152), 11 PRIMARY KEY (R_REGIONKEY)); 12 CREATE TABLE IF NOT EXISTS part ( P_PARTKEY INTEGER NOT NULL, 13 P_NAME VARCHAR(55) NOT NULL, 14 P_MFGR CHAR(25) NOT NULL, 15 P_BRAND CHAR(10) NOT NULL, 16 P_TYPE VARCHAR(25) NOT NULL, 17 P_SIZE INTEGER NOT NULL, 18 P_CONTAINER CHAR(10) NOT NULL, 19 P_RETAILPRICE DECIMAL(15,2) NOT NULL, 20 P_COMMENT VARCHAR(23) NOT NULL, 21 PRIMARY KEY (P_PARTKEY)); 22 CREATE TABLE IF NOT EXISTS supplier ( S_SUPPKEY INTEGER NOT NULL, 23 S_NAME CHAR(25) NOT NULL, 24 S_ADDRESS VARCHAR(40) NOT NULL, 25 S_NATIONKEY INTEGER NOT NULL, 26 S_PHONE CHAR(15) NOT NULL, 27 S_ACCTBAL DECIMAL(15,2) NOT NULL, 28 S_COMMENT VARCHAR(101) NOT NULL, 29 PRIMARY KEY (S_SUPPKEY), 30 CONSTRAINT FOREIGN KEY SUPPLIER_FK1 (S_NATIONKEY) references nation(N_NATIONKEY)); 31 CREATE TABLE IF NOT EXISTS partsupp ( PS_PARTKEY INTEGER NOT NULL, 32 PS_SUPPKEY INTEGER NOT NULL, 33 PS_AVAILQTY INTEGER NOT NULL, 34 PS_SUPPLYCOST DECIMAL(15,2) NOT NULL, 35 PS_COMMENT VARCHAR(199) NOT NULL, 36 PRIMARY KEY (PS_PARTKEY,PS_SUPPKEY), 37 CONSTRAINT FOREIGN KEY PARTSUPP_FK1 (PS_SUPPKEY) references supplier(S_SUPPKEY), 38 CONSTRAINT FOREIGN KEY PARTSUPP_FK2 (PS_PARTKEY) references part(P_PARTKEY)); 39 CREATE TABLE IF NOT EXISTS customer ( C_CUSTKEY INTEGER NOT NULL, 40 C_NAME VARCHAR(25) NOT NULL, 41 C_ADDRESS VARCHAR(40) NOT NULL, 42 C_NATIONKEY INTEGER NOT NULL, 43 C_PHONE CHAR(15) NOT NULL, 44 C_ACCTBAL DECIMAL(15,2) NOT NULL, 45 C_MKTSEGMENT CHAR(10) NOT NULL, 46 C_COMMENT VARCHAR(117) NOT NULL, 47 PRIMARY KEY (C_CUSTKEY), 48 CONSTRAINT FOREIGN KEY CUSTOMER_FK1 (C_NATIONKEY) references nation(N_NATIONKEY)); 49 CREATE TABLE IF NOT EXISTS orders ( O_ORDERKEY INTEGER NOT NULL, 50 O_CUSTKEY INTEGER NOT NULL, 51 O_ORDERSTATUS CHAR(1) NOT NULL, 52 O_TOTALPRICE DECIMAL(15,2) NOT NULL, 53 O_ORDERDATE DATE NOT NULL, 54 O_ORDERPRIORITY CHAR(15) NOT NULL, 55 O_CLERK CHAR(15) NOT NULL, 56 O_SHIPPRIORITY INTEGER NOT NULL, 57 O_COMMENT VARCHAR(79) NOT NULL, 58 PRIMARY KEY (O_ORDERKEY), 59 CONSTRAINT FOREIGN KEY ORDERS_FK1 (O_CUSTKEY) references customer(C_CUSTKEY)); 60 CREATE TABLE IF NOT EXISTS lineitem ( L_ORDERKEY INTEGER NOT NULL, 61 L_PARTKEY INTEGER NOT NULL, 62 L_SUPPKEY INTEGER NOT NULL, 63 L_LINENUMBER INTEGER NOT NULL, 64 L_QUANTITY DECIMAL(15,2) NOT NULL, 65 L_EXTENDEDPRICE DECIMAL(15,2) NOT NULL, 66 L_DISCOUNT DECIMAL(15,2) NOT NULL, 67 L_TAX DECIMAL(15,2) NOT NULL, 68 L_RETURNFLAG CHAR(1) NOT NULL, 69 L_LINESTATUS CHAR(1) NOT NULL, 70 L_SHIFIDelATE DATE NOT NULL, 71 L_COMMITDATE DATE NOT NULL, 72 L_RECEIPTDATE DATE NOT NULL, 73 L_SHIPINSTRUCT CHAR(25) NOT NULL, 74 L_SHIPMODE CHAR(10) NOT NULL, 75 L_COMMENT VARCHAR(44) NOT NULL, 76 PRIMARY KEY (L_ORDERKEY,L_LINENUMBER), 77 CONSTRAINT FOREIGN KEY LINEITEM_FK1 (L_ORDERKEY) references orders(O_ORDERKEY), 78 CONSTRAINT FOREIGN KEY LINEITEM_FK2 (L_PARTKEY,L_SUPPKEY) references partsupp(PS_PARTKEY, PS_SUPPKEY)); 79 load stats 's/tpch_stats/nation.json'; 80 load stats 's/tpch_stats/region.json'; 81 load stats 's/tpch_stats/part.json'; 82 load stats 's/tpch_stats/supplier.json'; 83 load stats 's/tpch_stats/partsupp.json'; 84 load stats 's/tpch_stats/customer.json'; 85 load stats 's/tpch_stats/orders.json'; 86 load stats 's/tpch_stats/lineitem.json'; 87 set @@stochastik.milevadb_opt_agg_push_down = 0; 88 /* 89 Q1 Pricing Summary Report 90 This query reports the amount of business that was billed, shipped, and returned. 91 The Pricing Summary Report Query provides a summary pricing report for all lineitems shipped as of a given date. 92 The date is within 60 - 120 days of the greatest ship date contained in the database. The query lists totals for 93 extended price, discounted extended price, discounted extended price plus tax, average quantity, average extended 94 price, and average discount. These aggregates are grouped by RETURNFLAG and LINESTATUS, and listed in 95 ascending order of RETURNFLAG and LINESTATUS. A count of the number of lineitems in each group is 96 included. 97 CausetAppend enhancement: none. 98 */ 99 explain 100 select 101 l_returnflag, 102 l_linestatus, 103 sum(l_quantity) as sum_qty, 104 sum(l_extendedprice) as sum_base_price, 105 sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, 106 sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, 107 avg(l_quantity) as avg_qty, 108 avg(l_extendedprice) as avg_price, 109 avg(l_discount) as avg_disc, 110 count(*) as count_order 111 from 112 lineitem 113 where 114 l_shiFIDelate <= date_sub('1998-12-01', interval 108 day) 115 group by 116 l_returnflag, 117 l_linestatus 118 order by 119 l_returnflag, 120 l_linestatus; 121 id estRows task access object operator info 122 Sort_6 2.94 root tpch.lineitem.l_returnflag, tpch.lineitem.l_linestatus 123 └─Projection_8 2.94 root tpch.lineitem.l_returnflag, tpch.lineitem.l_linestatus, DeferredCauset#18, DeferredCauset#19, DeferredCauset#20, DeferredCauset#21, DeferredCauset#22, DeferredCauset#23, DeferredCauset#24, DeferredCauset#25 124 └─HashAgg_14 2.94 root group by:tpch.lineitem.l_linestatus, tpch.lineitem.l_returnflag, funcs:sum(DeferredCauset#26)->DeferredCauset#18, funcs:sum(DeferredCauset#27)->DeferredCauset#19, funcs:sum(DeferredCauset#28)->DeferredCauset#20, funcs:sum(DeferredCauset#29)->DeferredCauset#21, funcs:avg(DeferredCauset#30, DeferredCauset#31)->DeferredCauset#22, funcs:avg(DeferredCauset#32, DeferredCauset#33)->DeferredCauset#23, funcs:avg(DeferredCauset#34, DeferredCauset#35)->DeferredCauset#24, funcs:count(DeferredCauset#36)->DeferredCauset#25, funcs:firstrow(tpch.lineitem.l_returnflag)->tpch.lineitem.l_returnflag, funcs:firstrow(tpch.lineitem.l_linestatus)->tpch.lineitem.l_linestatus 125 └─TableReader_15 2.94 root data:HashAgg_9 126 └─HashAgg_9 2.94 cop[einsteindb] group by:tpch.lineitem.l_linestatus, tpch.lineitem.l_returnflag, funcs:sum(tpch.lineitem.l_quantity)->DeferredCauset#26, funcs:sum(tpch.lineitem.l_extendedprice)->DeferredCauset#27, funcs:sum(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)))->DeferredCauset#28, funcs:sum(mul(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), plus(1, tpch.lineitem.l_tax)))->DeferredCauset#29, funcs:count(tpch.lineitem.l_quantity)->DeferredCauset#30, funcs:sum(tpch.lineitem.l_quantity)->DeferredCauset#31, funcs:count(tpch.lineitem.l_extendedprice)->DeferredCauset#32, funcs:sum(tpch.lineitem.l_extendedprice)->DeferredCauset#33, funcs:count(tpch.lineitem.l_discount)->DeferredCauset#34, funcs:sum(tpch.lineitem.l_discount)->DeferredCauset#35, funcs:count(1)->DeferredCauset#36 127 └─Selection_13 293795345.00 cop[einsteindb] le(tpch.lineitem.l_shiFIDelate, 1998-08-15) 128 └─TableFullScan_12 300005811.00 cop[einsteindb] causet:lineitem keep order:false 129 /* 130 Q2 Minimum Cost Supplier Query 131 This query finds which supplier should be selected to place an order for a given part in a given region. 132 The Minimum Cost Supplier Query finds, in a given region, for each part of a certain type and size, the supplier who 133 can supply it at minimum cost. If several suppliers in that region offer the desired part type and size at the same 134 (minimum) cost, the query lists the parts from suppliers with the 100 highest account balances. For each supplier, 135 the query lists the supplier's account balance, name and nation; the part's number and manufacturer; the supplier's 136 address, phone number and comment information. 137 CausetAppend enhancement: join reorder. 138 */ 139 explain 140 select 141 s_acctbal, 142 s_name, 143 n_name, 144 p_partkey, 145 p_mfgr, 146 s_address, 147 s_phone, 148 s_comment 149 from 150 part, 151 supplier, 152 partsupp, 153 nation, 154 region 155 where 156 p_partkey = ps_partkey 157 and s_suppkey = ps_suppkey 158 and p_size = 30 159 and p_type like '%STEEL' 160 and s_nationkey = n_nationkey 161 and n_regionkey = r_regionkey 162 and r_name = 'ASIA' 163 and ps_supplycost = ( 164 select 165 min(ps_supplycost) 166 from 167 partsupp, 168 supplier, 169 nation, 170 region 171 where 172 p_partkey = ps_partkey 173 and s_suppkey = ps_suppkey 174 and s_nationkey = n_nationkey 175 and n_regionkey = r_regionkey 176 and r_name = 'ASIA' 177 ) 178 order by 179 s_acctbal desc, 180 n_name, 181 s_name, 182 p_partkey 183 limit 100; 184 id estRows task access object operator info 185 Projection_37 100.00 root tpch.supplier.s_acctbal, tpch.supplier.s_name, tpch.nation.n_name, tpch.part.p_partkey, tpch.part.p_mfgr, tpch.supplier.s_address, tpch.supplier.s_phone, tpch.supplier.s_comment 186 └─TopN_40 100.00 root tpch.supplier.s_acctbal:desc, tpch.nation.n_name, tpch.supplier.s_name, tpch.part.p_partkey, offset:0, count:100 187 └─HashJoin_46 155496.00 root inner join, equal:[eq(tpch.part.p_partkey, tpch.partsupp.ps_partkey) eq(tpch.partsupp.ps_supplycost, DeferredCauset#50)] 188 ├─HashJoin_60(Build) 155496.00 root inner join, equal:[eq(tpch.partsupp.ps_partkey, tpch.part.p_partkey)] 189 │ ├─TableReader_90(Build) 155496.00 root data:Selection_89 190 │ │ └─Selection_89 155496.00 cop[einsteindb] eq(tpch.part.p_size, 30), like(tpch.part.p_type, "%STEEL", 92) 191 │ │ └─TableFullScan_88 10000000.00 cop[einsteindb] causet:part keep order:false 192 │ └─HashJoin_63(Probe) 8155010.44 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] 193 │ ├─HashJoin_65(Build) 100000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] 194 │ │ ├─HashJoin_78(Build) 5.00 root inner join, equal:[eq(tpch.region.r_regionkey, tpch.nation.n_regionkey)] 195 │ │ │ ├─TableReader_83(Build) 1.00 root data:Selection_82 196 │ │ │ │ └─Selection_82 1.00 cop[einsteindb] eq(tpch.region.r_name, "ASIA") 197 │ │ │ │ └─TableFullScan_81 5.00 cop[einsteindb] causet:region keep order:false 198 │ │ │ └─TableReader_80(Probe) 25.00 root data:TableFullScan_79 199 │ │ │ └─TableFullScan_79 25.00 cop[einsteindb] causet:nation keep order:false 200 │ │ └─TableReader_85(Probe) 500000.00 root data:TableFullScan_84 201 │ │ └─TableFullScan_84 500000.00 cop[einsteindb] causet:supplier keep order:false 202 │ └─TableReader_87(Probe) 40000000.00 root data:TableFullScan_86 203 │ └─TableFullScan_86 40000000.00 cop[einsteindb] causet:partsupp keep order:false 204 └─Selection_91(Probe) 6524008.35 root not(isnull(DeferredCauset#50)) 205 └─HashAgg_94 8155010.44 root group by:tpch.partsupp.ps_partkey, funcs:min(tpch.partsupp.ps_supplycost)->DeferredCauset#50, funcs:firstrow(tpch.partsupp.ps_partkey)->tpch.partsupp.ps_partkey 206 └─HashJoin_98 8155010.44 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] 207 ├─HashJoin_100(Build) 100000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] 208 │ ├─HashJoin_113(Build) 5.00 root inner join, equal:[eq(tpch.region.r_regionkey, tpch.nation.n_regionkey)] 209 │ │ ├─TableReader_118(Build) 1.00 root data:Selection_117 210 │ │ │ └─Selection_117 1.00 cop[einsteindb] eq(tpch.region.r_name, "ASIA") 211 │ │ │ └─TableFullScan_116 5.00 cop[einsteindb] causet:region keep order:false 212 │ │ └─TableReader_115(Probe) 25.00 root data:TableFullScan_114 213 │ │ └─TableFullScan_114 25.00 cop[einsteindb] causet:nation keep order:false 214 │ └─TableReader_120(Probe) 500000.00 root data:TableFullScan_119 215 │ └─TableFullScan_119 500000.00 cop[einsteindb] causet:supplier keep order:false 216 └─TableReader_122(Probe) 40000000.00 root data:TableFullScan_121 217 └─TableFullScan_121 40000000.00 cop[einsteindb] causet:partsupp keep order:false 218 /* 219 Q3 Shipping Priority Query 220 This query retrieves the 10 unshipped orders with the highest value. 221 The Shipping Priority Query retrieves the shipping priority and potential revenue, defined as the sum of 222 l_extendedprice * (1-l_discount), of the orders having the largest revenue among those that had not been shipped as 223 of a given date. Orders are listed in decreasing order of revenue. If more than 10 unshipped orders exist, only the 10 224 orders with the largest revenue are listed. 225 causet enhancement: if group-by item have primary key, non-priamry key is useless. 226 */ 227 explain 228 select 229 l_orderkey, 230 sum(l_extendedprice * (1 - l_discount)) as revenue, 231 o_orderdate, 232 o_shippriority 233 from 234 customer, 235 orders, 236 lineitem 237 where 238 c_mktsegment = 'AUTOMOBILE' 239 and c_custkey = o_custkey 240 and l_orderkey = o_orderkey 241 and o_orderdate < '1995-03-13' 242 and l_shiFIDelate > '1995-03-13' 243 group by 244 l_orderkey, 245 o_orderdate, 246 o_shippriority 247 order by 248 revenue desc, 249 o_orderdate 250 limit 10; 251 id estRows task access object operator info 252 Projection_14 10.00 root tpch.lineitem.l_orderkey, DeferredCauset#35, tpch.orders.o_orderdate, tpch.orders.o_shippriority 253 └─TopN_17 10.00 root DeferredCauset#35:desc, tpch.orders.o_orderdate, offset:0, count:10 254 └─HashAgg_23 40252367.98 root group by:DeferredCauset#48, DeferredCauset#49, DeferredCauset#50, funcs:sum(DeferredCauset#44)->DeferredCauset#35, funcs:firstrow(DeferredCauset#45)->tpch.orders.o_orderdate, funcs:firstrow(DeferredCauset#46)->tpch.orders.o_shippriority, funcs:firstrow(DeferredCauset#47)->tpch.lineitem.l_orderkey 255 └─Projection_81 91515927.49 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->DeferredCauset#44, tpch.orders.o_orderdate, tpch.orders.o_shippriority, tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey, tpch.orders.o_orderdate, tpch.orders.o_shippriority 256 └─HashJoin_40 91515927.49 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] 257 ├─HashJoin_71(Build) 22592975.51 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] 258 │ ├─TableReader_77(Build) 1498236.00 root data:Selection_76 259 │ │ └─Selection_76 1498236.00 cop[einsteindb] eq(tpch.customer.c_mktsegment, "AUTOMOBILE") 260 │ │ └─TableFullScan_75 7500000.00 cop[einsteindb] causet:customer keep order:false 261 │ └─TableReader_74(Probe) 36870000.00 root data:Selection_73 262 │ └─Selection_73 36870000.00 cop[einsteindb] lt(tpch.orders.o_orderdate, 1995-03-13 00:00:00.000000) 263 │ └─TableFullScan_72 75000000.00 cop[einsteindb] causet:orders keep order:false 264 └─TableReader_80(Probe) 163047704.27 root data:Selection_79 265 └─Selection_79 163047704.27 cop[einsteindb] gt(tpch.lineitem.l_shiFIDelate, 1995-03-13 00:00:00.000000) 266 └─TableFullScan_78 300005811.00 cop[einsteindb] causet:lineitem keep order:false 267 /* 268 Q4 Order Priority Checking Query 269 This query determines how well the order priority system is working and gives an assessment of customer satisfaction. 270 The Order Priority Checking Query counts the number of orders ordered in a given quarter of a given year in which 271 at least one lineitem was received by the customer later than its committed date. The query lists the count of such 272 orders for each order priority sorted in ascending priority order. 273 */ 274 explain 275 select 276 o_orderpriority, 277 count(*) as order_count 278 from 279 orders 280 where 281 o_orderdate >= '1995-01-01' 282 and o_orderdate < date_add('1995-01-01', interval '3' month) 283 and exists ( 284 select 285 * 286 from 287 lineitem 288 where 289 l_orderkey = o_orderkey 290 and l_commitdate < l_receiptdate 291 ) 292 group by 293 o_orderpriority 294 order by 295 o_orderpriority; 296 id estRows task access object operator info 297 Sort_10 1.00 root tpch.orders.o_orderpriority 298 └─Projection_12 1.00 root tpch.orders.o_orderpriority, DeferredCauset#27 299 └─HashAgg_15 1.00 root group by:tpch.orders.o_orderpriority, funcs:count(1)->DeferredCauset#27, funcs:firstrow(tpch.orders.o_orderpriority)->tpch.orders.o_orderpriority 300 └─IndexHashJoin_23 2340750.00 root semi join, inner:IndexLookUp_20, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey 301 ├─TableReader_42(Build) 2925937.50 root data:Selection_41 302 │ └─Selection_41 2925937.50 cop[einsteindb] ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), lt(tpch.orders.o_orderdate, 1995-04-01) 303 │ └─TableFullScan_40 75000000.00 cop[einsteindb] causet:orders keep order:false 304 └─IndexLookUp_20(Probe) 4.05 root 305 ├─IndexRangeScan_17(Build) 5.06 cop[einsteindb] causet:lineitem, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) range: decided by [eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)], keep order:false 306 └─Selection_19(Probe) 4.05 cop[einsteindb] lt(tpch.lineitem.l_commitdate, tpch.lineitem.l_receiptdate) 307 └─TableRowIDScan_18 5.06 cop[einsteindb] causet:lineitem keep order:false 308 /* 309 Q5 Local Supplier Volume Query 310 This query lists the revenue volume done through local suppliers. 311 The Local Supplier Volume Query lists for each nation in a region the revenue volume that resulted from lineitem 312 transactions in which the customer ordering parts and the supplier filling them were both within that nation. The 313 query is run in order to determine whether to institute local distribution centers in a given region. The query considers 314 only parts ordered in a given year. The query displays the nations and revenue volume in descending order by 315 revenue. Revenue volume for all qualifying lineitems in a particular nation is defined as sum(l_extendedprice * (1 - 316 l_discount)). 317 CausetAppend enhancement: join reorder. 318 */ 319 explain 320 select 321 n_name, 322 sum(l_extendedprice * (1 - l_discount)) as revenue 323 from 324 customer, 325 orders, 326 lineitem, 327 supplier, 328 nation, 329 region 330 where 331 c_custkey = o_custkey 332 and l_orderkey = o_orderkey 333 and l_suppkey = s_suppkey 334 and c_nationkey = s_nationkey 335 and s_nationkey = n_nationkey 336 and n_regionkey = r_regionkey 337 and r_name = 'MIDBSE EAST' 338 and o_orderdate >= '1994-01-01' 339 and o_orderdate < date_add('1994-01-01', interval '1' year) 340 group by 341 n_name 342 order by 343 revenue desc; 344 id estRows task access object operator info 345 Sort_23 5.00 root DeferredCauset#49:desc 346 └─Projection_25 5.00 root tpch.nation.n_name, DeferredCauset#49 347 └─HashAgg_28 5.00 root group by:DeferredCauset#52, funcs:sum(DeferredCauset#50)->DeferredCauset#49, funcs:firstrow(DeferredCauset#51)->tpch.nation.n_name 348 └─Projection_86 11822812.50 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->DeferredCauset#50, tpch.nation.n_name, tpch.nation.n_name 349 └─HashJoin_38 11822812.50 root inner join, equal:[eq(tpch.supplier.s_nationkey, tpch.customer.c_nationkey) eq(tpch.orders.o_custkey, tpch.customer.c_custkey)] 350 ├─TableReader_84(Build) 7500000.00 root data:TableFullScan_83 351 │ └─TableFullScan_83 7500000.00 cop[einsteindb] causet:customer keep order:false 352 └─HashJoin_52(Probe) 11822812.50 root inner join, equal:[eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)] 353 ├─TableReader_82(Build) 11822812.50 root data:Selection_81 354 │ └─Selection_81 11822812.50 cop[einsteindb] ge(tpch.orders.o_orderdate, 1994-01-01 00:00:00.000000), lt(tpch.orders.o_orderdate, 1995-01-01) 355 │ └─TableFullScan_80 75000000.00 cop[einsteindb] causet:orders keep order:false 356 └─HashJoin_55(Probe) 61163763.01 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.lineitem.l_suppkey)] 357 ├─HashJoin_57(Build) 100000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] 358 │ ├─HashJoin_70(Build) 5.00 root inner join, equal:[eq(tpch.region.r_regionkey, tpch.nation.n_regionkey)] 359 │ │ ├─TableReader_75(Build) 1.00 root data:Selection_74 360 │ │ │ └─Selection_74 1.00 cop[einsteindb] eq(tpch.region.r_name, "MIDBSE EAST") 361 │ │ │ └─TableFullScan_73 5.00 cop[einsteindb] causet:region keep order:false 362 │ │ └─TableReader_72(Probe) 25.00 root data:TableFullScan_71 363 │ │ └─TableFullScan_71 25.00 cop[einsteindb] causet:nation keep order:false 364 │ └─TableReader_77(Probe) 500000.00 root data:TableFullScan_76 365 │ └─TableFullScan_76 500000.00 cop[einsteindb] causet:supplier keep order:false 366 └─TableReader_79(Probe) 300005811.00 root data:TableFullScan_78 367 └─TableFullScan_78 300005811.00 cop[einsteindb] causet:lineitem keep order:false 368 /* 369 Q6 Forecasting Revenue Change Query 370 This query quantifies the amount of revenue increase that would have resulted from eliminating certain companywide 371 discounts in a given percentage range in a given year. Asking this type of "what if" query can be used to look 372 for ways to increase revenues. 373 The Forecasting Revenue Change Query considers all the lineitems shipped in a given year with discounts between 374 DISCOUNT-0.01 and DISCOUNT+0.01. The query lists the amount by which the total revenue would have 375 increased if these discounts had been eliminated for lineitems with l_quantity less than quantity. Note that the 376 potential revenue increase is equal to the sum of [l_extendedprice * l_discount] for all lineitems with discounts and 377 quantities in the qualifying range. 378 */ 379 explain 380 select 381 sum(l_extendedprice * l_discount) as revenue 382 from 383 lineitem 384 where 385 l_shiFIDelate >= '1994-01-01' 386 and l_shiFIDelate < date_add('1994-01-01', interval '1' year) 387 and l_discount between 0.06 - 0.01 and 0.06 + 0.01 388 and l_quantity < 24; 389 id estRows task access object operator info 390 StreamAgg_20 1.00 root funcs:sum(DeferredCauset#20)->DeferredCauset#18 391 └─TableReader_21 1.00 root data:StreamAgg_9 392 └─StreamAgg_9 1.00 cop[einsteindb] funcs:sum(mul(tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount))->DeferredCauset#20 393 └─Selection_19 3713857.91 cop[einsteindb] ge(tpch.lineitem.l_discount, 0.05), ge(tpch.lineitem.l_shiFIDelate, 1994-01-01 00:00:00.000000), le(tpch.lineitem.l_discount, 0.07), lt(tpch.lineitem.l_quantity, 24), lt(tpch.lineitem.l_shiFIDelate, 1995-01-01) 394 └─TableFullScan_18 300005811.00 cop[einsteindb] causet:lineitem keep order:false 395 /* 396 Q7 Volume Shipping Query 397 This query determines the value of goods shipped between certain nations to help in the re-negotiation of shipping 398 contracts. 399 The Volume Shipping Query finds, for two given nations, the gross discounted revenues derived from lineitems in 400 which parts were shipped from a supplier in either nation to a customer in the other nation during 1995 and 1996. 401 The query lists the supplier nation, the customer nation, the year, and the revenue from shipments that took place in 402 that year. The query orders the answer by Supplier nation, Customer nation, and year (all ascending). 403 CausetAppend enahancement: join reorder. 404 */ 405 explain 406 select 407 supp_nation, 408 cust_nation, 409 l_year, 410 sum(volume) as revenue 411 from 412 ( 413 select 414 n1.n_name as supp_nation, 415 n2.n_name as cust_nation, 416 extract(year from l_shiFIDelate) as l_year, 417 l_extendedprice * (1 - l_discount) as volume 418 from 419 supplier, 420 lineitem, 421 orders, 422 customer, 423 nation n1, 424 nation n2 425 where 426 s_suppkey = l_suppkey 427 and o_orderkey = l_orderkey 428 and c_custkey = o_custkey 429 and s_nationkey = n1.n_nationkey 430 and c_nationkey = n2.n_nationkey 431 and ( 432 (n1.n_name = 'JAPAN' and n2.n_name = 'INDIA') 433 or (n1.n_name = 'INDIA' and n2.n_name = 'JAPAN') 434 ) 435 and l_shiFIDelate between '1995-01-01' and '1996-12-31' 436 ) as shipping 437 group by 438 supp_nation, 439 cust_nation, 440 l_year 441 order by 442 supp_nation, 443 cust_nation, 444 l_year; 445 id estRows task access object operator info 446 Sort_22 769.96 root tpch.nation.n_name, tpch.nation.n_name, DeferredCauset#50 447 └─Projection_24 769.96 root tpch.nation.n_name, tpch.nation.n_name, DeferredCauset#50, DeferredCauset#52 448 └─HashAgg_27 769.96 root group by:DeferredCauset#50, tpch.nation.n_name, tpch.nation.n_name, funcs:sum(DeferredCauset#51)->DeferredCauset#52, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(DeferredCauset#50)->DeferredCauset#50 449 └─Projection_28 1957240.42 root tpch.nation.n_name, tpch.nation.n_name, extract(YEAR, tpch.lineitem.l_shiFIDelate)->DeferredCauset#50, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->DeferredCauset#51 450 └─HashJoin_40 1957240.42 root inner join, equal:[eq(tpch.customer.c_nationkey, tpch.nation.n_nationkey)], other cond:or(and(eq(tpch.nation.n_name, "JAPAN"), eq(tpch.nation.n_name, "INDIA")), and(eq(tpch.nation.n_name, "INDIA"), eq(tpch.nation.n_name, "JAPAN"))) 451 ├─TableReader_94(Build) 2.00 root data:Selection_93 452 │ └─Selection_93 2.00 cop[einsteindb] or(eq(tpch.nation.n_name, "INDIA"), eq(tpch.nation.n_name, "JAPAN")) 453 │ └─TableFullScan_92 25.00 cop[einsteindb] causet:n2 keep order:false 454 └─HashJoin_51(Probe) 24465505.20 root inner join, equal:[eq(tpch.orders.o_custkey, tpch.customer.c_custkey)] 455 ├─TableReader_91(Build) 7500000.00 root data:TableFullScan_90 456 │ └─TableFullScan_90 7500000.00 cop[einsteindb] causet:customer keep order:false 457 └─IndexMergeJoin_62(Probe) 24465505.20 root inner join, inner:TableReader_57, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey 458 ├─HashJoin_66(Build) 24465505.20 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.lineitem.l_suppkey)] 459 │ ├─HashJoin_79(Build) 40000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] 460 │ │ ├─TableReader_84(Build) 2.00 root data:Selection_83 461 │ │ │ └─Selection_83 2.00 cop[einsteindb] or(eq(tpch.nation.n_name, "JAPAN"), eq(tpch.nation.n_name, "INDIA")) 462 │ │ │ └─TableFullScan_82 25.00 cop[einsteindb] causet:n1 keep order:false 463 │ │ └─TableReader_81(Probe) 500000.00 root data:TableFullScan_80 464 │ │ └─TableFullScan_80 500000.00 cop[einsteindb] causet:supplier keep order:false 465 │ └─TableReader_87(Probe) 91446230.29 root data:Selection_86 466 │ └─Selection_86 91446230.29 cop[einsteindb] ge(tpch.lineitem.l_shiFIDelate, 1995-01-01 00:00:00.000000), le(tpch.lineitem.l_shiFIDelate, 1996-12-31 00:00:00.000000) 467 │ └─TableFullScan_85 300005811.00 cop[einsteindb] causet:lineitem keep order:false 468 └─TableReader_57(Probe) 1.00 root data:TableRangeScan_56 469 └─TableRangeScan_56 1.00 cop[einsteindb] causet:orders range: decided by [tpch.lineitem.l_orderkey], keep order:true 470 /* 471 Q8 National Market Share Query 472 This query determines how the market share of a given nation within a given region has changed over two years for 473 a given part type. 474 The market share for a given nation within a given region is defined as the fraction of the revenue, the sum of 475 [l_extendedprice * (1-l_discount)], from the products of a specified type in that region that was supplied by suppliers 476 from the given nation. The query determines this for the years 1995 and 1996 presented in this order. 477 CausetAppend enhancement: join reorder. 478 */ 479 explain 480 select 481 o_year, 482 sum(case 483 when nation = 'INDIA' then volume 484 else 0 485 end) / sum(volume) as mkt_share 486 from 487 ( 488 select 489 extract(year from o_orderdate) as o_year, 490 l_extendedprice * (1 - l_discount) as volume, 491 n2.n_name as nation 492 from 493 part, 494 supplier, 495 lineitem, 496 orders, 497 customer, 498 nation n1, 499 nation n2, 500 region 501 where 502 p_partkey = l_partkey 503 and s_suppkey = l_suppkey 504 and l_orderkey = o_orderkey 505 and o_custkey = c_custkey 506 and c_nationkey = n1.n_nationkey 507 and n1.n_regionkey = r_regionkey 508 and r_name = 'ASIA' 509 and s_nationkey = n2.n_nationkey 510 and o_orderdate between '1995-01-01' and '1996-12-31' 511 and p_type = 'SMALL PLATED COPPER' 512 ) as all_nations 513 group by 514 o_year 515 order by 516 o_year; 517 id estRows task access object operator info 518 Sort_29 719.02 root DeferredCauset#62 519 └─Projection_31 719.02 root DeferredCauset#62, div(DeferredCauset#64, DeferredCauset#65)->DeferredCauset#66 520 └─HashAgg_34 719.02 root group by:DeferredCauset#78, funcs:sum(DeferredCauset#75)->DeferredCauset#64, funcs:sum(DeferredCauset#76)->DeferredCauset#65, funcs:firstrow(DeferredCauset#77)->DeferredCauset#62 521 └─Projection_123 563136.02 root case(eq(tpch.nation.n_name, INDIA), DeferredCauset#63, 0)->DeferredCauset#75, DeferredCauset#63, DeferredCauset#62, DeferredCauset#62 522 └─Projection_35 563136.02 root extract(YEAR, tpch.orders.o_orderdate)->DeferredCauset#62, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->DeferredCauset#63, tpch.nation.n_name 523 └─HashJoin_45 563136.02 root inner join, equal:[eq(tpch.supplier.s_nationkey, tpch.nation.n_nationkey)] 524 ├─TableReader_121(Build) 25.00 root data:TableFullScan_120 525 │ └─TableFullScan_120 25.00 cop[einsteindb] causet:n2 keep order:false 526 └─HashJoin_56(Probe) 563136.02 root inner join, equal:[eq(tpch.lineitem.l_suppkey, tpch.supplier.s_suppkey)] 527 ├─TableReader_119(Build) 500000.00 root data:TableFullScan_118 528 │ └─TableFullScan_118 500000.00 cop[einsteindb] causet:supplier keep order:false 529 └─HashJoin_69(Probe) 563136.02 root inner join, equal:[eq(tpch.lineitem.l_partkey, tpch.part.p_partkey)] 530 ├─TableReader_117(Build) 61674.00 root data:Selection_116 531 │ └─Selection_116 61674.00 cop[einsteindb] eq(tpch.part.p_type, "SMALL PLATED COPPER") 532 │ └─TableFullScan_115 10000000.00 cop[einsteindb] causet:part keep order:false 533 └─IndexHashJoin_77(Probe) 90788402.51 root inner join, inner:IndexLookUp_74, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey 534 ├─HashJoin_87(Build) 22413367.93 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] 535 │ ├─HashJoin_89(Build) 1500000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.customer.c_nationkey)] 536 │ │ ├─HashJoin_102(Build) 5.00 root inner join, equal:[eq(tpch.region.r_regionkey, tpch.nation.n_regionkey)] 537 │ │ │ ├─TableReader_107(Build) 1.00 root data:Selection_106 538 │ │ │ │ └─Selection_106 1.00 cop[einsteindb] eq(tpch.region.r_name, "ASIA") 539 │ │ │ │ └─TableFullScan_105 5.00 cop[einsteindb] causet:region keep order:false 540 │ │ │ └─TableReader_104(Probe) 25.00 root data:TableFullScan_103 541 │ │ │ └─TableFullScan_103 25.00 cop[einsteindb] causet:n1 keep order:false 542 │ │ └─TableReader_109(Probe) 7500000.00 root data:TableFullScan_108 543 │ │ └─TableFullScan_108 7500000.00 cop[einsteindb] causet:customer keep order:false 544 │ └─TableReader_112(Probe) 22413367.93 root data:Selection_111 545 │ └─Selection_111 22413367.93 cop[einsteindb] ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), le(tpch.orders.o_orderdate, 1996-12-31 00:00:00.000000) 546 │ └─TableFullScan_110 75000000.00 cop[einsteindb] causet:orders keep order:false 547 └─IndexLookUp_74(Probe) 4.05 root 548 ├─IndexRangeScan_72(Build) 4.05 cop[einsteindb] causet:lineitem, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) range: decided by [eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)], keep order:false 549 └─TableRowIDScan_73(Probe) 4.05 cop[einsteindb] causet:lineitem keep order:false 550 /* 551 Q9 Product Type Profit Measure Query 552 This query determines how much profit is made on a given line of parts, broken out by supplier nation and year. 553 The Product Type Profit Measure Query finds, for each nation and each year, the profit for all parts ordered in that 554 year that contain a specified substring in their names and that were filled by a supplier in that nation. The profit is 555 defined as the sum of [(l_extendedprice*(1-l_discount)) - (ps_supplycost * l_quantity)] for all lineitems describing 556 parts in the specified line. The query lists the nations in ascending alphabetical order and, for each nation, the year 557 and profit in descending order by year (most recent first). 558 CausetAppend enhancement: join reorder. 559 */ 560 explain 561 select 562 nation, 563 o_year, 564 sum(amount) as sum_profit 565 from 566 ( 567 select 568 n_name as nation, 569 extract(year from o_orderdate) as o_year, 570 l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount 571 from 572 part, 573 supplier, 574 lineitem, 575 partsupp, 576 orders, 577 nation 578 where 579 s_suppkey = l_suppkey 580 and ps_suppkey = l_suppkey 581 and ps_partkey = l_partkey 582 and p_partkey = l_partkey 583 and o_orderkey = l_orderkey 584 and s_nationkey = n_nationkey 585 and p_name like '%dim%' 586 ) as profit 587 group by 588 nation, 589 o_year 590 order by 591 nation, 592 o_year desc; 593 id estRows task access object operator info 594 Sort_25 2406.00 root tpch.nation.n_name, DeferredCauset#53:desc 595 └─Projection_27 2406.00 root tpch.nation.n_name, DeferredCauset#53, DeferredCauset#55 596 └─HashAgg_30 2406.00 root group by:DeferredCauset#53, tpch.nation.n_name, funcs:sum(DeferredCauset#54)->DeferredCauset#55, funcs:firstrow(tpch.nation.n_name)->tpch.nation.n_name, funcs:firstrow(DeferredCauset#53)->DeferredCauset#53 597 └─Projection_31 971049283.51 root tpch.nation.n_name, extract(YEAR, tpch.orders.o_orderdate)->DeferredCauset#53, minus(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), mul(tpch.partsupp.ps_supplycost, tpch.lineitem.l_quantity))->DeferredCauset#54 598 └─HashJoin_44 971049283.51 root inner join, equal:[eq(tpch.lineitem.l_suppkey, tpch.partsupp.ps_suppkey) eq(tpch.lineitem.l_partkey, tpch.partsupp.ps_partkey)] 599 ├─TableReader_106(Build) 40000000.00 root data:TableFullScan_105 600 │ └─TableFullScan_105 40000000.00 cop[einsteindb] causet:partsupp keep order:false 601 └─HashJoin_56(Probe) 241379546.70 root inner join, equal:[eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)] 602 ├─TableReader_104(Build) 75000000.00 root data:TableFullScan_103 603 │ └─TableFullScan_103 75000000.00 cop[einsteindb] causet:orders keep order:false 604 └─HashJoin_79(Probe) 241379546.70 root inner join, equal:[eq(tpch.lineitem.l_partkey, tpch.part.p_partkey)] 605 ├─TableReader_102(Build) 8000000.00 root data:Selection_101 606 │ └─Selection_101 8000000.00 cop[einsteindb] like(tpch.part.p_name, "%dim%", 92) 607 │ └─TableFullScan_100 10000000.00 cop[einsteindb] causet:part keep order:false 608 └─HashJoin_82(Probe) 300005811.00 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.lineitem.l_suppkey)] 609 ├─HashJoin_93(Build) 500000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] 610 │ ├─TableReader_97(Build) 25.00 root data:TableFullScan_96 611 │ │ └─TableFullScan_96 25.00 cop[einsteindb] causet:nation keep order:false 612 │ └─TableReader_95(Probe) 500000.00 root data:TableFullScan_94 613 │ └─TableFullScan_94 500000.00 cop[einsteindb] causet:supplier keep order:false 614 └─TableReader_99(Probe) 300005811.00 root data:TableFullScan_98 615 └─TableFullScan_98 300005811.00 cop[einsteindb] causet:lineitem keep order:false 616 /* 617 Q10 Returned Item Reporting Query 618 The query identifies customers who might be having problems with the parts that are shipped to them. 619 The Returned Item Reporting Query finds the top 20 customers, in terms of their effect on lost revenue for a given 620 quarter, who have returned parts. The query considers only parts that were ordered in the specified quarter. The 621 query lists the customer's name, address, nation, phone number, account balance, comment information and revenue 622 lost. The customers are listed in descending order of lost revenue. Revenue lost is defined as 623 sum(l_extendedprice*(1-l_discount)) for all qualifying lineitems. 624 CausetAppend enhancement: join reorder, if group-by item have primary key, non-priamry key is useless. 625 */ 626 explain 627 select 628 c_custkey, 629 c_name, 630 sum(l_extendedprice * (1 - l_discount)) as revenue, 631 c_acctbal, 632 n_name, 633 c_address, 634 c_phone, 635 c_comment 636 from 637 customer, 638 orders, 639 lineitem, 640 nation 641 where 642 c_custkey = o_custkey 643 and l_orderkey = o_orderkey 644 and o_orderdate >= '1993-08-01' 645 and o_orderdate < date_add('1993-08-01', interval '3' month) 646 and l_returnflag = 'R' 647 and c_nationkey = n_nationkey 648 group by 649 c_custkey, 650 c_name, 651 c_acctbal, 652 c_phone, 653 n_name, 654 c_address, 655 c_comment 656 order by 657 revenue desc 658 limit 20; 659 id estRows task access object operator info 660 Projection_17 20.00 root tpch.customer.c_custkey, tpch.customer.c_name, DeferredCauset#39, tpch.customer.c_acctbal, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_comment 661 └─TopN_20 20.00 root DeferredCauset#39:desc, offset:0, count:20 662 └─HashAgg_26 3017307.69 root group by:DeferredCauset#53, DeferredCauset#54, DeferredCauset#55, DeferredCauset#56, DeferredCauset#57, DeferredCauset#58, DeferredCauset#59, funcs:sum(DeferredCauset#45)->DeferredCauset#39, funcs:firstrow(DeferredCauset#46)->tpch.customer.c_custkey, funcs:firstrow(DeferredCauset#47)->tpch.customer.c_name, funcs:firstrow(DeferredCauset#48)->tpch.customer.c_address, funcs:firstrow(DeferredCauset#49)->tpch.customer.c_phone, funcs:firstrow(DeferredCauset#50)->tpch.customer.c_acctbal, funcs:firstrow(DeferredCauset#51)->tpch.customer.c_comment, funcs:firstrow(DeferredCauset#52)->tpch.nation.n_name 663 └─Projection_67 12222016.17 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->DeferredCauset#45, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_acctbal, tpch.customer.c_comment, tpch.nation.n_name, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_acctbal, tpch.customer.c_phone, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_comment 664 └─IndexHashJoin_34 12222016.17 root inner join, inner:IndexLookUp_31, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey 665 ├─HashJoin_44(Build) 3017307.69 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] 666 │ ├─TableReader_63(Build) 3017307.69 root data:Selection_62 667 │ │ └─Selection_62 3017307.69 cop[einsteindb] ge(tpch.orders.o_orderdate, 1993-08-01 00:00:00.000000), lt(tpch.orders.o_orderdate, 1993-11-01) 668 │ │ └─TableFullScan_61 75000000.00 cop[einsteindb] causet:orders keep order:false 669 │ └─HashJoin_56(Probe) 7500000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.customer.c_nationkey)] 670 │ ├─TableReader_60(Build) 25.00 root data:TableFullScan_59 671 │ │ └─TableFullScan_59 25.00 cop[einsteindb] causet:nation keep order:false 672 │ └─TableReader_58(Probe) 7500000.00 root data:TableFullScan_57 673 │ └─TableFullScan_57 7500000.00 cop[einsteindb] causet:customer keep order:false 674 └─IndexLookUp_31(Probe) 4.05 root 675 ├─IndexRangeScan_28(Build) 16.44 cop[einsteindb] causet:lineitem, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) range: decided by [eq(tpch.lineitem.l_orderkey, tpch.orders.o_orderkey)], keep order:false 676 └─Selection_30(Probe) 4.05 cop[einsteindb] eq(tpch.lineitem.l_returnflag, "R") 677 └─TableRowIDScan_29 16.44 cop[einsteindb] causet:lineitem keep order:false 678 /* 679 Q11 Important Stock Identification Query 680 This query finds the most important subset of suppliers' stock in a given nation. 681 The Important Stock Identification Query finds, from scanning the available stock of suppliers in a given nation, all 682 the parts that represent a significant percentage of the total value of all available parts. The query displays the part 683 number and the value of those parts in descending order of value. 684 */ 685 explain 686 select 687 ps_partkey, 688 sum(ps_supplycost * ps_availqty) as value 689 from 690 partsupp, 691 supplier, 692 nation 693 where 694 ps_suppkey = s_suppkey 695 and s_nationkey = n_nationkey 696 and n_name = 'MOZAMBIQUE' 697 group by 698 ps_partkey having 699 sum(ps_supplycost * ps_availqty) > ( 700 select 701 sum(ps_supplycost * ps_availqty) * 0.0001000000 702 from 703 partsupp, 704 supplier, 705 nation 706 where 707 ps_suppkey = s_suppkey 708 and s_nationkey = n_nationkey 709 and n_name = 'MOZAMBIQUE' 710 ) 711 order by 712 value desc; 713 id estRows task access object operator info 714 Projection_57 1304801.67 root tpch.partsupp.ps_partkey, DeferredCauset#18 715 └─Sort_58 1304801.67 root DeferredCauset#18:desc 716 └─Selection_60 1304801.67 root gt(DeferredCauset#18, NULL) 717 └─HashAgg_63 1631002.09 root group by:DeferredCauset#44, funcs:sum(DeferredCauset#42)->DeferredCauset#18, funcs:firstrow(DeferredCauset#43)->tpch.partsupp.ps_partkey 718 └─Projection_89 1631002.09 root mul(tpch.partsupp.ps_supplycost, cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY))->DeferredCauset#42, tpch.partsupp.ps_partkey, tpch.partsupp.ps_partkey 719 └─HashJoin_67 1631002.09 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] 720 ├─HashJoin_80(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] 721 │ ├─TableReader_85(Build) 1.00 root data:Selection_84 722 │ │ └─Selection_84 1.00 cop[einsteindb] eq(tpch.nation.n_name, "MOZAMBIQUE") 723 │ │ └─TableFullScan_83 25.00 cop[einsteindb] causet:nation keep order:false 724 │ └─TableReader_82(Probe) 500000.00 root data:TableFullScan_81 725 │ └─TableFullScan_81 500000.00 cop[einsteindb] causet:supplier keep order:false 726 └─TableReader_87(Probe) 40000000.00 root data:TableFullScan_86 727 └─TableFullScan_86 40000000.00 cop[einsteindb] causet:partsupp keep order:false 728 /* 729 Q12 Shipping Modes and Order Priority Query 730 This query determines whether selecting less expensive modes of shipping is negatively affecting the critical-priority 731 orders by causing more parts to be received by customers after the committed date. 732 The Shipping Modes and Order Priority Query counts, by ship mode, for lineitems actually received by customers in 733 a given year, the number of lineitems belonging to orders for which the l_receiptdate exceeds the l_commitdate for 734 two different specified ship modes. Only lineitems that were actually shipped before the l_commitdate are considered. 735 The late lineitems are partitioned into two groups, those with priority URGENT or HIGH, and those with a 736 priority other than URGENT or HIGH. 737 */ 738 explain 739 select 740 l_shipmode, 741 sum(case 742 when o_orderpriority = '1-URGENT' 743 or o_orderpriority = '2-HIGH' 744 then 1 745 else 0 746 end) as high_line_count, 747 sum(case 748 when o_orderpriority <> '1-URGENT' 749 and o_orderpriority <> '2-HIGH' 750 then 1 751 else 0 752 end) as low_line_count 753 from 754 orders, 755 lineitem 756 where 757 o_orderkey = l_orderkey 758 and l_shipmode in ('RAIL', 'FOB') 759 and l_commitdate < l_receiptdate 760 and l_shiFIDelate < l_commitdate 761 and l_receiptdate >= '1997-01-01' 762 and l_receiptdate < date_add('1997-01-01', interval '1' year) 763 group by 764 l_shipmode 765 order by 766 l_shipmode; 767 id estRows task access object operator info 768 Sort_9 1.00 root tpch.lineitem.l_shipmode 769 └─Projection_11 1.00 root tpch.lineitem.l_shipmode, DeferredCauset#27, DeferredCauset#28 770 └─HashAgg_14 1.00 root group by:DeferredCauset#40, funcs:sum(DeferredCauset#37)->DeferredCauset#27, funcs:sum(DeferredCauset#38)->DeferredCauset#28, funcs:firstrow(DeferredCauset#39)->tpch.lineitem.l_shipmode 771 └─Projection_54 10023369.01 root cast(case(or(eq(tpch.orders.o_orderpriority, 1-URGENT), eq(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(65,0) BINARY)->DeferredCauset#37, cast(case(and(ne(tpch.orders.o_orderpriority, 1-URGENT), ne(tpch.orders.o_orderpriority, 2-HIGH)), 1, 0), decimal(65,0) BINARY)->DeferredCauset#38, tpch.lineitem.l_shipmode, tpch.lineitem.l_shipmode 772 └─IndexMergeJoin_24 10023369.01 root inner join, inner:TableReader_19, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey 773 ├─TableReader_50(Build) 10023369.01 root data:Selection_49 774 │ └─Selection_49 10023369.01 cop[einsteindb] ge(tpch.lineitem.l_receiptdate, 1997-01-01 00:00:00.000000), in(tpch.lineitem.l_shipmode, "RAIL", "FOB"), lt(tpch.lineitem.l_commitdate, tpch.lineitem.l_receiptdate), lt(tpch.lineitem.l_receiptdate, 1998-01-01), lt(tpch.lineitem.l_shiFIDelate, tpch.lineitem.l_commitdate) 775 │ └─TableFullScan_48 300005811.00 cop[einsteindb] causet:lineitem keep order:false 776 └─TableReader_19(Probe) 1.00 root data:TableRangeScan_18 777 └─TableRangeScan_18 1.00 cop[einsteindb] causet:orders range: decided by [tpch.lineitem.l_orderkey], keep order:true 778 /* 779 Q13 Customer Distribution Query 780 This query seeks relationships between customers and the size of their orders. 781 This query determines the distribution of customers by the number of orders they have made, including customers 782 who have no record of orders, past or present. It counts and reports how many customers have no orders, how many 783 have 1, 2, 3, etc. A check is made to ensure that the orders counted do not fall into one of several special categories 784 of orders. Special categories are identified in the order comment column by looking for a particular pattern. 785 */ 786 explain 787 select 788 c_count, 789 count(*) as custdist 790 from 791 ( 792 select 793 c_custkey, 794 count(o_orderkey) as c_count 795 from 796 customer left outer join orders on 797 c_custkey = o_custkey 798 and o_comment not like '%pending%deposits%' 799 group by 800 c_custkey 801 ) c_orders 802 group by 803 c_count 804 order by 805 custdist desc, 806 c_count desc; 807 id estRows task access object operator info 808 Sort_9 7500000.00 root DeferredCauset#19:desc, DeferredCauset#18:desc 809 └─Projection_11 7500000.00 root DeferredCauset#18, DeferredCauset#19 810 └─HashAgg_14 7500000.00 root group by:DeferredCauset#18, funcs:count(1)->DeferredCauset#19, funcs:firstrow(DeferredCauset#18)->DeferredCauset#18 811 └─HashAgg_17 7500000.00 root group by:tpch.customer.c_custkey, funcs:count(tpch.orders.o_orderkey)->DeferredCauset#18 812 └─HashJoin_21 60000000.00 root left outer join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] 813 ├─TableReader_23(Build) 7500000.00 root data:TableFullScan_22 814 │ └─TableFullScan_22 7500000.00 cop[einsteindb] causet:customer keep order:false 815 └─TableReader_26(Probe) 60000000.00 root data:Selection_25 816 └─Selection_25 60000000.00 cop[einsteindb] not(like(tpch.orders.o_comment, "%pending%deposits%", 92)) 817 └─TableFullScan_24 75000000.00 cop[einsteindb] causet:orders keep order:false 818 /* 819 Q14 Promotion Effect Query 820 This query monitors the market response to a promotion such as TV advertisements or a special campaign. 821 The Promotion Effect Query determines what percentage of the revenue in a given year and month was derived from 822 promotional parts. The query considers only parts actually shipped in that month and gives the percentage. Revenue 823 is defined as (l_extendedprice * (1-l_discount)). 824 */ 825 explain 826 select 827 100.00 * sum(case 828 when p_type like 'PROMO%' 829 then l_extendedprice * (1 - l_discount) 830 else 0 831 end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue 832 from 833 lineitem, 834 part 835 where 836 l_partkey = p_partkey 837 and l_shiFIDelate >= '1996-12-01' 838 and l_shiFIDelate < date_add('1996-12-01', interval '1' month); 839 id estRows task access object operator info 840 Projection_8 1.00 root div(mul(100.00, DeferredCauset#27), DeferredCauset#28)->DeferredCauset#29 841 └─StreamAgg_13 1.00 root funcs:sum(DeferredCauset#31)->DeferredCauset#27, funcs:sum(DeferredCauset#32)->DeferredCauset#28 842 └─Projection_41 4121984.49 root case(like(tpch.part.p_type, PROMO%, 92), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), 0)->DeferredCauset#31, mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->DeferredCauset#32 843 └─IndexMergeJoin_38 4121984.49 root inner join, inner:TableReader_33, outer key:tpch.lineitem.l_partkey, inner key:tpch.part.p_partkey 844 ├─TableReader_27(Build) 4121984.49 root data:Selection_26 845 │ └─Selection_26 4121984.49 cop[einsteindb] ge(tpch.lineitem.l_shiFIDelate, 1996-12-01 00:00:00.000000), lt(tpch.lineitem.l_shiFIDelate, 1997-01-01) 846 │ └─TableFullScan_25 300005811.00 cop[einsteindb] causet:lineitem keep order:false 847 └─TableReader_33(Probe) 1.00 root data:TableRangeScan_32 848 └─TableRangeScan_32 1.00 cop[einsteindb] causet:part range: decided by [tpch.lineitem.l_partkey], keep order:true 849 /* 850 Q15 Top Supplier Query 851 This query determines the top supplier so it can be rewarded, given more business, or identified for special recognition. 852 The Top Supplier Query finds the supplier who contributed the most to the overall revenue for parts shipped during 853 a given quarter of a given year. In case of a tie, the query lists all suppliers whose contribution was equal to the 854 maximum, presented in supplier number order. 855 CausetAppend enhancement: support view. 856 create view revenue0 (supplier_no, total_revenue) as 857 select 858 l_suppkey, 859 sum(l_extendedprice * (1 - l_discount)) 860 from 861 lineitem 862 where 863 l_shiFIDelate >= '1997-07-01' 864 and l_shiFIDelate < date_add('1997-07-01', interval '3' month) 865 group by 866 l_suppkey 867 select 868 s_suppkey, 869 s_name, 870 s_address, 871 s_phone, 872 total_revenue 873 from 874 supplier, 875 revenue0 876 where 877 s_suppkey = supplier_no 878 and total_revenue = ( 879 select 880 max(total_revenue) 881 from 882 revenue0 883 ) 884 order by 885 s_suppkey 886 drop view revenue0 887 */ 888 /* 889 Q16 Parts/Supplier Relationship Query 890 This query finds out how many suppliers can supply parts with given attributes. It might be used, for example, to 891 determine whether there is a sufficient number of suppliers for heavily ordered parts. 892 The Parts/Supplier Relationship Query counts the number of suppliers who can supply parts that satisfy a particular 893 customer's requirements. The customer is interested in parts of eight different sizes as long as they are not of a given 894 type, not of a given brand, and not from a supplier who has had complaints registered at the Better Business Bureau. 895 Results must be presented in descending count and ascending brand, type, and size. 896 */ 897 explain 898 select 899 p_brand, 900 p_type, 901 p_size, 902 count(distinct ps_suppkey) as supplier_cnt 903 from 904 partsupp, 905 part 906 where 907 p_partkey = ps_partkey 908 and p_brand <> 'Brand#34' 909 and p_type not like 'LARGE BRUSHED%' 910 and p_size in (48, 19, 12, 4, 41, 7, 21, 39) 911 and ps_suppkey not in ( 912 select 913 s_suppkey 914 from 915 supplier 916 where 917 s_comment like '%Customer%Complaints%' 918 ) 919 group by 920 p_brand, 921 p_type, 922 p_size 923 order by 924 supplier_cnt desc, 925 p_brand, 926 p_type, 927 p_size; 928 id estRows task access object operator info 929 Sort_13 14.41 root DeferredCauset#23:desc, tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size 930 └─Projection_15 14.41 root tpch.part.p_brand, tpch.part.p_type, tpch.part.p_size, DeferredCauset#23 931 └─HashAgg_16 14.41 root group by:tpch.part.p_brand, tpch.part.p_size, tpch.part.p_type, funcs:count(distinct tpch.partsupp.ps_suppkey)->DeferredCauset#23, funcs:firstrow(tpch.part.p_brand)->tpch.part.p_brand, funcs:firstrow(tpch.part.p_type)->tpch.part.p_type, funcs:firstrow(tpch.part.p_size)->tpch.part.p_size 932 └─HashJoin_28 3863988.24 root anti semi join, equal:[eq(tpch.partsupp.ps_suppkey, tpch.supplier.s_suppkey)] 933 ├─TableReader_66(Build) 400000.00 root data:Selection_65 934 │ └─Selection_65 400000.00 cop[einsteindb] like(tpch.supplier.s_comment, "%Customer%Complaints%", 92) 935 │ └─TableFullScan_64 500000.00 cop[einsteindb] causet:supplier keep order:false 936 └─IndexMergeJoin_38(Probe) 4829985.30 root inner join, inner:IndexReader_36, outer key:tpch.part.p_partkey, inner key:tpch.partsupp.ps_partkey 937 ├─TableReader_59(Build) 1200618.43 root data:Selection_58 938 │ └─Selection_58 1200618.43 cop[einsteindb] in(tpch.part.p_size, 48, 19, 12, 4, 41, 7, 21, 39), ne(tpch.part.p_brand, "Brand#34"), not(like(tpch.part.p_type, "LARGE BRUSHED%", 92)) 939 │ └─TableFullScan_57 10000000.00 cop[einsteindb] causet:part keep order:false 940 └─IndexReader_36(Probe) 4.02 root index:IndexRangeScan_35 941 └─IndexRangeScan_35 4.02 cop[einsteindb] causet:partsupp, index:PRIMARY(PS_PARTKEY, PS_SUPPKEY) range: decided by [eq(tpch.partsupp.ps_partkey, tpch.part.p_partkey)], keep order:true 942 /* 943 Q17 Small-Quantity-Order Revenue Query 944 This query determines how much average yearly revenue would be lost if orders were no longer filled for small 945 quantities of certain parts. This may reduce overhead expenses by concentrating sales on larger shipments. 946 The Small-Quantity-Order Revenue Query considers parts of a given brand and with a given container type and 947 determines the average lineitem quantity of such parts ordered for all orders (past and pending) in the 7-year database. 948 What would be the average yearly gross (undiscounted) loss in revenue if orders for these parts with a quantity 949 of less than 20% of this average were no longer taken? 950 CausetAppend enahancement: aggregation pull up through join. 951 */ 952 explain 953 select 954 sum(l_extendedprice) / 7.0 as avg_yearly 955 from 956 lineitem, 957 part 958 where 959 p_partkey = l_partkey 960 and p_brand = 'Brand#44' 961 and p_container = 'WRAP PKG' 962 and l_quantity < ( 963 select 964 0.2 * avg(l_quantity) 965 from 966 lineitem 967 where 968 l_partkey = p_partkey 969 ); 970 id estRows task access object operator info 971 Projection_16 1.00 root div(DeferredCauset#46, 7.0)->DeferredCauset#47 972 └─StreamAgg_21 1.00 root funcs:sum(tpch.lineitem.l_extendedprice)->DeferredCauset#46 973 └─HashJoin_53 293773.83 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)], other cond:lt(tpch.lineitem.l_quantity, mul(0.2, DeferredCauset#44)) 974 ├─HashJoin_37(Build) 293773.83 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)] 975 │ ├─TableReader_42(Build) 9736.49 root data:Selection_41 976 │ │ └─Selection_41 9736.49 cop[einsteindb] eq(tpch.part.p_brand, "Brand#44"), eq(tpch.part.p_container, "WRAP PKG") 977 │ │ └─TableFullScan_40 10000000.00 cop[einsteindb] causet:part keep order:false 978 │ └─TableReader_39(Probe) 300005811.00 root data:TableFullScan_38 979 │ └─TableFullScan_38 300005811.00 cop[einsteindb] causet:lineitem keep order:false 980 └─HashAgg_47(Probe) 9943040.00 root group by:tpch.lineitem.l_partkey, funcs:avg(DeferredCauset#50, DeferredCauset#51)->DeferredCauset#44, funcs:firstrow(tpch.lineitem.l_partkey)->tpch.lineitem.l_partkey 981 └─TableReader_48 9943040.00 root data:HashAgg_43 982 └─HashAgg_43 9943040.00 cop[einsteindb] group by:tpch.lineitem.l_partkey, funcs:count(tpch.lineitem.l_quantity)->DeferredCauset#50, funcs:sum(tpch.lineitem.l_quantity)->DeferredCauset#51 983 └─TableFullScan_46 300005811.00 cop[einsteindb] causet:lineitem keep order:false 984 /* 985 Q18 Large Volume Customer Query 986 The Large Volume Customer Query ranks customers based on their having placed a large quantity order. Large 987 quantity orders are defined as those orders whose total quantity is above a certain level. 988 The Large Volume Customer Query finds a list of the top 100 customers who have ever placed large quantity orders. 989 The query lists the customer name, customer key, the order key, date and total price and the quantity for the order. 990 CausetAppend enhancement: cost estimation is not so good, join reorder. The inner subquery's result is only 300+ rows. 991 */ 992 explain 993 select 994 c_name, 995 c_custkey, 996 o_orderkey, 997 o_orderdate, 998 o_totalprice, 999 sum(l_quantity) 1000 from 1001 customer, 1002 orders, 1003 lineitem 1004 where 1005 o_orderkey in ( 1006 select 1007 l_orderkey 1008 from 1009 lineitem 1010 group by 1011 l_orderkey having 1012 sum(l_quantity) > 314 1013 ) 1014 and c_custkey = o_custkey 1015 and o_orderkey = l_orderkey 1016 group by 1017 c_name, 1018 c_custkey, 1019 o_orderkey, 1020 o_orderdate, 1021 o_totalprice 1022 order by 1023 o_totalprice desc, 1024 o_orderdate 1025 limit 100; 1026 id estRows task access object operator info 1027 Projection_24 100.00 root tpch.customer.c_name, tpch.customer.c_custkey, tpch.orders.o_orderkey, tpch.orders.o_orderdate, tpch.orders.o_totalprice, DeferredCauset#54 1028 └─TopN_27 100.00 root tpch.orders.o_totalprice:desc, tpch.orders.o_orderdate, offset:0, count:100 1029 └─HashAgg_33 59251097.60 root group by:tpch.customer.c_custkey, tpch.customer.c_name, tpch.orders.o_orderdate, tpch.orders.o_orderkey, tpch.orders.o_totalprice, funcs:sum(tpch.lineitem.l_quantity)->DeferredCauset#54, funcs:firstrow(tpch.customer.c_custkey)->tpch.customer.c_custkey, funcs:firstrow(tpch.customer.c_name)->tpch.customer.c_name, funcs:firstrow(tpch.orders.o_orderkey)->tpch.orders.o_orderkey, funcs:firstrow(tpch.orders.o_totalprice)->tpch.orders.o_totalprice, funcs:firstrow(tpch.orders.o_orderdate)->tpch.orders.o_orderdate 1030 └─HashJoin_48 240004648.80 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] 1031 ├─HashJoin_72(Build) 59251097.60 root inner join, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] 1032 │ ├─Selection_89(Build) 59251097.60 root gt(DeferredCauset#52, 314) 1033 │ │ └─HashAgg_96 74063872.00 root group by:tpch.lineitem.l_orderkey, funcs:sum(DeferredCauset#66)->DeferredCauset#52, funcs:firstrow(tpch.lineitem.l_orderkey)->tpch.lineitem.l_orderkey 1034 │ │ └─TableReader_97 74063872.00 root data:HashAgg_90 1035 │ │ └─HashAgg_90 74063872.00 cop[einsteindb] group by:tpch.lineitem.l_orderkey, funcs:sum(tpch.lineitem.l_quantity)->DeferredCauset#66 1036 │ │ └─TableFullScan_95 300005811.00 cop[einsteindb] causet:lineitem keep order:false 1037 │ └─HashJoin_84(Probe) 75000000.00 root inner join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] 1038 │ ├─TableReader_88(Build) 7500000.00 root data:TableFullScan_87 1039 │ │ └─TableFullScan_87 7500000.00 cop[einsteindb] causet:customer keep order:false 1040 │ └─TableReader_86(Probe) 75000000.00 root data:TableFullScan_85 1041 │ └─TableFullScan_85 75000000.00 cop[einsteindb] causet:orders keep order:false 1042 └─TableReader_101(Probe) 300005811.00 root data:TableFullScan_100 1043 └─TableFullScan_100 300005811.00 cop[einsteindb] causet:lineitem keep order:false 1044 /* 1045 Q19 Discounted Revenue Query 1046 The Discounted Revenue Query reports the gross discounted revenue attributed to the sale of selected parts handled 1047 in a particular manner. This query is an example of code such as might be produced programmatically by a data 1048 mining tool. 1049 The Discounted Revenue query finds the gross discounted revenue for all orders for three different types of parts 1050 that were shipped by air and delivered in person. Parts are selected based on the combination of specific brands, a 1051 list of containers, and a range of sizes. 1052 */ 1053 explain 1054 select 1055 sum(l_extendedprice* (1 - l_discount)) as revenue 1056 from 1057 lineitem, 1058 part 1059 where 1060 ( 1061 p_partkey = l_partkey 1062 and p_brand = 'Brand#52' 1063 and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') 1064 and l_quantity >= 4 and l_quantity <= 4 + 10 1065 and p_size between 1 and 5 1066 and l_shipmode in ('AIR', 'AIR REG') 1067 and l_shipinstruct = 'DELIVER IN PERSON' 1068 ) 1069 or 1070 ( 1071 p_partkey = l_partkey 1072 and p_brand = 'Brand#11' 1073 and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') 1074 and l_quantity >= 18 and l_quantity <= 18 + 10 1075 and p_size between 1 and 10 1076 and l_shipmode in ('AIR', 'AIR REG') 1077 and l_shipinstruct = 'DELIVER IN PERSON' 1078 ) 1079 or 1080 ( 1081 p_partkey = l_partkey 1082 and p_brand = 'Brand#51' 1083 and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') 1084 and l_quantity >= 29 and l_quantity <= 29 + 10 1085 and p_size between 1 and 15 1086 and l_shipmode in ('AIR', 'AIR REG') 1087 and l_shipinstruct = 'DELIVER IN PERSON' 1088 ); 1089 id estRows task access object operator info 1090 StreamAgg_13 1.00 root funcs:sum(DeferredCauset#28)->DeferredCauset#27 1091 └─Projection_46 733887.82 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount))->DeferredCauset#28 1092 └─HashJoin_45 733887.82 root inner join, equal:[eq(tpch.part.p_partkey, tpch.lineitem.l_partkey)], other cond:or(and(and(eq(tpch.part.p_brand, "Brand#52"), in(tpch.part.p_container, "SM CASE", "SM BOX", "SM PACK", "SM PKG")), and(ge(tpch.lineitem.l_quantity, 4), and(le(tpch.lineitem.l_quantity, 14), le(tpch.part.p_size, 5)))), or(and(and(eq(tpch.part.p_brand, "Brand#11"), in(tpch.part.p_container, "MED BAG", "MED BOX", "MED PKG", "MED PACK")), and(ge(tpch.lineitem.l_quantity, 18), and(le(tpch.lineitem.l_quantity, 28), le(tpch.part.p_size, 10)))), and(and(eq(tpch.part.p_brand, "Brand#51"), in(tpch.part.p_container, "LG CASE", "LG BOX", "LG PACK", "LG PKG")), and(ge(tpch.lineitem.l_quantity, 29), and(le(tpch.lineitem.l_quantity, 39), le(tpch.part.p_size, 15)))))) 1093 ├─TableReader_32(Build) 24323.12 root data:Selection_31 1094 │ └─Selection_31 24323.12 cop[einsteindb] ge(tpch.part.p_size, 1), or(and(eq(tpch.part.p_brand, "Brand#52"), and(in(tpch.part.p_container, "SM CASE", "SM BOX", "SM PACK", "SM PKG"), le(tpch.part.p_size, 5))), or(and(eq(tpch.part.p_brand, "Brand#11"), and(in(tpch.part.p_container, "MED BAG", "MED BOX", "MED PKG", "MED PACK"), le(tpch.part.p_size, 10))), and(eq(tpch.part.p_brand, "Brand#51"), and(in(tpch.part.p_container, "LG CASE", "LG BOX", "LG PACK", "LG PKG"), le(tpch.part.p_size, 15))))) 1095 │ └─TableFullScan_30 10000000.00 cop[einsteindb] causet:part keep order:false 1096 └─TableReader_29(Probe) 6286493.79 root data:Selection_28 1097 └─Selection_28 6286493.79 cop[einsteindb] eq(tpch.lineitem.l_shipinstruct, "DELIVER IN PERSON"), in(tpch.lineitem.l_shipmode, "AIR", "AIR REG"), or(and(ge(tpch.lineitem.l_quantity, 4), le(tpch.lineitem.l_quantity, 14)), or(and(ge(tpch.lineitem.l_quantity, 18), le(tpch.lineitem.l_quantity, 28)), and(ge(tpch.lineitem.l_quantity, 29), le(tpch.lineitem.l_quantity, 39)))) 1098 └─TableFullScan_27 300005811.00 cop[einsteindb] causet:lineitem keep order:false 1099 /* 1100 Q20 Potential Part Promotion Query 1101 The Potential Part Promotion Query identifies suppliers in a particular nation having selected parts that may be candidates 1102 for a promotional offer. 1103 The Potential Part Promotion query identifies suppliers who have an excess of a given part available; an excess is 1104 defined to be more than 50% of the parts like the given part that the supplier shipped in a given year for a given 1105 nation. Only parts whose names share a certain naming convention are considered. 1106 */ 1107 explain 1108 select 1109 s_name, 1110 s_address 1111 from 1112 supplier, 1113 nation 1114 where 1115 s_suppkey in ( 1116 select 1117 ps_suppkey 1118 from 1119 partsupp 1120 where 1121 ps_partkey in ( 1122 select 1123 p_partkey 1124 from 1125 part 1126 where 1127 p_name like 'green%' 1128 ) 1129 and ps_availqty > ( 1130 select 1131 0.5 * sum(l_quantity) 1132 from 1133 lineitem 1134 where 1135 l_partkey = ps_partkey 1136 and l_suppkey = ps_suppkey 1137 and l_shiFIDelate >= '1993-01-01' 1138 and l_shiFIDelate < date_add('1993-01-01', interval '1' year) 1139 ) 1140 ) 1141 and s_nationkey = n_nationkey 1142 and n_name = 'ALGERIA' 1143 order by 1144 s_name; 1145 id estRows task access object operator info 1146 Sort_28 20000.00 root tpch.supplier.s_name 1147 └─HashJoin_32 20000.00 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] 1148 ├─HashJoin_45(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] 1149 │ ├─TableReader_50(Build) 1.00 root data:Selection_49 1150 │ │ └─Selection_49 1.00 cop[einsteindb] eq(tpch.nation.n_name, "ALGERIA") 1151 │ │ └─TableFullScan_48 25.00 cop[einsteindb] causet:nation keep order:false 1152 │ └─TableReader_47(Probe) 500000.00 root data:TableFullScan_46 1153 │ └─TableFullScan_46 500000.00 cop[einsteindb] causet:supplier keep order:false 1154 └─HashAgg_53(Probe) 257492.04 root group by:tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey 1155 └─Projection_54 257492.04 root tpch.partsupp.ps_suppkey 1156 └─Selection_55 257492.04 root gt(cast(tpch.partsupp.ps_availqty), mul(0.5, DeferredCauset#44)) 1157 └─HashAgg_58 321865.05 root group by:tpch.partsupp.ps_partkey, tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_suppkey)->tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_availqty)->tpch.partsupp.ps_availqty, funcs:sum(tpch.lineitem.l_quantity)->DeferredCauset#44 1158 └─HashJoin_62 9711455.06 root left outer join, equal:[eq(tpch.partsupp.ps_partkey, tpch.lineitem.l_partkey) eq(tpch.partsupp.ps_suppkey, tpch.lineitem.l_suppkey)] 1159 ├─IndexHashJoin_69(Build) 321865.05 root inner join, inner:IndexLookUp_66, outer key:tpch.part.p_partkey, inner key:tpch.partsupp.ps_partkey 1160 │ ├─TableReader_98(Build) 80007.93 root data:Selection_97 1161 │ │ └─Selection_97 80007.93 cop[einsteindb] like(tpch.part.p_name, "green%", 92) 1162 │ │ └─TableFullScan_96 10000000.00 cop[einsteindb] causet:part keep order:false 1163 │ └─IndexLookUp_66(Probe) 4.02 root 1164 │ ├─IndexRangeScan_64(Build) 4.02 cop[einsteindb] causet:partsupp, index:PRIMARY(PS_PARTKEY, PS_SUPPKEY) range: decided by [eq(tpch.partsupp.ps_partkey, tpch.part.p_partkey)], keep order:false 1165 │ └─TableRowIDScan_65(Probe) 4.02 cop[einsteindb] causet:partsupp keep order:false 1166 └─TableReader_103(Probe) 44189356.65 root data:Selection_102 1167 └─Selection_102 44189356.65 cop[einsteindb] ge(tpch.lineitem.l_shiFIDelate, 1993-01-01 00:00:00.000000), lt(tpch.lineitem.l_shiFIDelate, 1994-01-01) 1168 └─TableFullScan_101 300005811.00 cop[einsteindb] causet:lineitem keep order:false 1169 /* 1170 Q21 Suppliers Who Kept Orders Waiting Query 1171 This query identifies certain suppliers who were not able to ship required parts in a timely manner. 1172 The Suppliers Who Kept Orders Waiting query identifies suppliers, for a given nation, whose product was part of a 1173 multi-supplier order (with current status of 'F') where they were the only supplier who failed to meet the committed 1174 delivery date. 1175 */ 1176 explain 1177 select 1178 s_name, 1179 count(*) as numwait 1180 from 1181 supplier, 1182 lineitem l1, 1183 orders, 1184 nation 1185 where 1186 s_suppkey = l1.l_suppkey 1187 and o_orderkey = l1.l_orderkey 1188 and o_orderstatus = 'F' 1189 and l1.l_receiptdate > l1.l_commitdate 1190 and exists ( 1191 select 1192 * 1193 from 1194 lineitem l2 1195 where 1196 l2.l_orderkey = l1.l_orderkey 1197 and l2.l_suppkey <> l1.l_suppkey 1198 ) 1199 and not exists ( 1200 select 1201 * 1202 from 1203 lineitem l3 1204 where 1205 l3.l_orderkey = l1.l_orderkey 1206 and l3.l_suppkey <> l1.l_suppkey 1207 and l3.l_receiptdate > l3.l_commitdate 1208 ) 1209 and s_nationkey = n_nationkey 1210 and n_name = 'EGYPT' 1211 group by 1212 s_name 1213 order by 1214 numwait desc, 1215 s_name 1216 limit 100; 1217 id estRows task access object operator info 1218 Projection_25 100.00 root tpch.supplier.s_name, DeferredCauset#72 1219 └─TopN_28 100.00 root DeferredCauset#72:desc, tpch.supplier.s_name, offset:0, count:100 1220 └─HashAgg_34 12800.00 root group by:tpch.supplier.s_name, funcs:count(1)->DeferredCauset#72, funcs:firstrow(tpch.supplier.s_name)->tpch.supplier.s_name 1221 └─IndexHashJoin_42 7828961.66 root anti semi join, inner:IndexLookUp_39, outer key:tpch.lineitem.l_orderkey, inner key:tpch.lineitem.l_orderkey, other cond:ne(tpch.lineitem.l_suppkey, tpch.lineitem.l_suppkey) 1222 ├─IndexHashJoin_82(Build) 9786202.08 root semi join, inner:IndexLookUp_79, outer key:tpch.lineitem.l_orderkey, inner key:tpch.lineitem.l_orderkey, other cond:ne(tpch.lineitem.l_suppkey, tpch.lineitem.l_suppkey), ne(tpch.lineitem.l_suppkey, tpch.supplier.s_suppkey) 1223 │ ├─IndexMergeJoin_101(Build) 12232752.60 root inner join, inner:TableReader_96, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey 1224 │ │ ├─HashJoin_105(Build) 12232752.60 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.lineitem.l_suppkey)] 1225 │ │ │ ├─HashJoin_118(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] 1226 │ │ │ │ ├─TableReader_123(Build) 1.00 root data:Selection_122 1227 │ │ │ │ │ └─Selection_122 1.00 cop[einsteindb] eq(tpch.nation.n_name, "EGYPT") 1228 │ │ │ │ │ └─TableFullScan_121 25.00 cop[einsteindb] causet:nation keep order:false 1229 │ │ │ │ └─TableReader_120(Probe) 500000.00 root data:TableFullScan_119 1230 │ │ │ │ └─TableFullScan_119 500000.00 cop[einsteindb] causet:supplier keep order:false 1231 │ │ │ └─TableReader_126(Probe) 240004648.80 root data:Selection_125 1232 │ │ │ └─Selection_125 240004648.80 cop[einsteindb] gt(tpch.lineitem.l_receiptdate, tpch.lineitem.l_commitdate) 1233 │ │ │ └─TableFullScan_124 300005811.00 cop[einsteindb] causet:l1 keep order:false 1234 │ │ └─TableReader_96(Probe) 0.49 root data:Selection_95 1235 │ │ └─Selection_95 0.49 cop[einsteindb] eq(tpch.orders.o_orderstatus, "F") 1236 │ │ └─TableRangeScan_94 1.00 cop[einsteindb] causet:orders range: decided by [tpch.lineitem.l_orderkey], keep order:true 1237 │ └─IndexLookUp_79(Probe) 4.05 root 1238 │ ├─IndexRangeScan_77(Build) 4.05 cop[einsteindb] causet:l2, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) range: decided by [eq(tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey)], keep order:false 1239 │ └─TableRowIDScan_78(Probe) 4.05 cop[einsteindb] causet:l2 keep order:false 1240 └─IndexLookUp_39(Probe) 4.05 root 1241 ├─IndexRangeScan_36(Build) 5.06 cop[einsteindb] causet:l3, index:PRIMARY(L_ORDERKEY, L_LINENUMBER) range: decided by [eq(tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey)], keep order:false 1242 └─Selection_38(Probe) 4.05 cop[einsteindb] gt(tpch.lineitem.l_receiptdate, tpch.lineitem.l_commitdate) 1243 └─TableRowIDScan_37 5.06 cop[einsteindb] causet:l3 keep order:false 1244 /* 1245 Q22 Global Sales Opportunity Query 1246 The Global Sales Opportunity Query identifies geographies where there are customers who may be likely to make a 1247 purchase. 1248 This query counts how many customers within a specific range of country codes have not placed orders for 7 years 1249 but who have a greater than average “positive” account balance. It also reflects the magnitude of that balance. 1250 Country code is defined as the first two characters of c_phone. 1251 */ 1252 explain 1253 select 1254 cntrycode, 1255 count(*) as numcust, 1256 sum(c_acctbal) as totacctbal 1257 from 1258 ( 1259 select 1260 substring(c_phone from 1 for 2) as cntrycode, 1261 c_acctbal 1262 from 1263 customer 1264 where 1265 substring(c_phone from 1 for 2) in 1266 ('20', '40', '22', '30', '39', '42', '21') 1267 and c_acctbal > ( 1268 select 1269 avg(c_acctbal) 1270 from 1271 customer 1272 where 1273 c_acctbal > 0.00 1274 and substring(c_phone from 1 for 2) in 1275 ('20', '40', '22', '30', '39', '42', '21') 1276 ) 1277 and not exists ( 1278 select 1279 * 1280 from 1281 orders 1282 where 1283 o_custkey = c_custkey 1284 ) 1285 ) as custsale 1286 group by 1287 cntrycode 1288 order by 1289 cntrycode; 1290 id estRows task access object operator info 1291 Sort_39 1.00 root DeferredCauset#27 1292 └─Projection_41 1.00 root DeferredCauset#27, DeferredCauset#28, DeferredCauset#29 1293 └─HashAgg_44 1.00 root group by:DeferredCauset#27, funcs:count(1)->DeferredCauset#28, funcs:sum(tpch.customer.c_acctbal)->DeferredCauset#29, funcs:firstrow(DeferredCauset#27)->DeferredCauset#27 1294 └─Projection_45 0.00 root substring(tpch.customer.c_phone, 1, 2)->DeferredCauset#27, tpch.customer.c_acctbal 1295 └─HashJoin_46 0.00 root anti semi join, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] 1296 ├─TableReader_52(Build) 75000000.00 root data:TableFullScan_51 1297 │ └─TableFullScan_51 75000000.00 cop[einsteindb] causet:orders keep order:false 1298 └─Selection_50(Probe) 0.00 root in(substring(tpch.customer.c_phone, 1, 2), "20", "40", "22", "30", "39", "42", "21") 1299 └─TableReader_49 0.00 root data:Selection_48 1300 └─Selection_48 0.00 cop[einsteindb] gt(tpch.customer.c_acctbal, NULL) 1301 └─TableFullScan_47 7500000.00 cop[einsteindb] causet:customer keep order:false