--
-- MULTI_LARGE_SHARDID
--
-- Load data into distributed tables, and run TPC-H query #1 and #6. This test
-- differs from previous tests in that it modifies the *internal* shardId
-- generator, forcing the distributed database to use 64-bit shard identifiers.
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 100200300400500;
-- Load additional data to start using large shard identifiers.
\copy lineitem FROM '@abs_srcdir@/data/lineitem.1.data' with delimiter '|'
\copy lineitem FROM '@abs_srcdir@/data/lineitem.2.data' with delimiter '|'
-- Query #1 from the TPC-H decision support benchmark.
SELECT
	l_returnflag,
	l_linestatus,
	sum(l_quantity) as sum_qty,
	sum(l_extendedprice) as sum_base_price,
	sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
	sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
	avg(l_quantity) as avg_qty,
	avg(l_extendedprice) as avg_price,
	avg(l_discount) as avg_disc,
	count(*) as count_order
FROM
	lineitem
WHERE
	l_shipdate <= date '1998-12-01' - interval '90 days'
GROUP BY
	l_returnflag,
	l_linestatus
ORDER BY
	l_returnflag,
	l_linestatus;
 l_returnflag | l_linestatus |  sum_qty  | sum_base_price | sum_disc_price |    sum_charge    |       avg_qty       |     avg_price      |        avg_disc        | count_order 
--------------+--------------+-----------+----------------+----------------+------------------+---------------------+--------------------+------------------------+-------------
 A            | F            | 150930.00 |   227239747.26 | 215682574.1456 | 224342306.491846 | 25.6334918478260870 | 38593.707075407609 | 0.05055027173913043478 |        5888
 N            | F            |   4044.00 |     6205102.90 |   5905081.4236 |   6145285.541304 | 26.6052631578947368 | 40823.045394736842 | 0.05263157894736842105 |         152
 N            | O            | 299556.00 |   449413896.32 | 427269715.3708 | 444268143.859602 | 25.4594594594594595 | 38195.979629440762 | 0.04939486656467788543 |       11766
 R            | F            | 146312.00 |   217875959.46 | 207033247.3396 | 215487067.568656 | 25.2175112030334367 | 37551.871675284385 | 0.04983798690106859704 |        5802
(4 rows)

-- Query #6 from the TPC-H decision support benchmark.
SELECT
	sum(l_extendedprice * l_discount) as revenue
FROM
	lineitem
WHERE
	l_shipdate >= date '1994-01-01'
	and l_shipdate < date '1994-01-01' + interval '1 year'
	and l_discount between 0.06 - 0.01 and 0.06 + 0.01
	and l_quantity < 24;
   revenue   
-------------
 486555.5716
(1 row)

