--
-- 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;
CREATE TABLE lineitem_large_shard_id AS SELECT * FROM lineitem;
SELECT create_distributed_table('lineitem_large_shard_id', 'l_orderkey');
NOTICE:  Copying data from local table...
NOTICE:  copying the data has completed
DETAIL:  The local data in the table is no longer visible, but is still on disk.
HINT:  To remove the local data, run: SELECT truncate_local_data_after_distributing_table($$public.lineitem_large_shard_id$$)
 create_distributed_table
---------------------------------------------------------------------

(1 row)

-- 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_large_shard_id
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            |  75465.00 |   113619873.63 | 107841287.0728 | 112171153.245923 | 25.6334918478260870 | 38593.707075407609 | 0.05055027173913043478 |        2944
 N            | F            |   2022.00 |     3102551.45 |   2952540.7118 |   3072642.770652 | 26.6052631578947368 | 40823.045394736842 | 0.05263157894736842105 |          76
 N            | O            | 149778.00 |   224706948.16 | 213634857.6854 | 222134071.929801 | 25.4594594594594595 | 38195.979629440762 | 0.04939486656467788543 |        5883
 R            | F            |  73156.00 |   108937979.73 | 103516623.6698 | 107743533.784328 | 25.2175112030334367 | 37551.871675284385 | 0.04983798690106859704 |        2901
(4 rows)

-- Query #6 from the TPC-H decision support benchmark.
SELECT
	sum(l_extendedprice * l_discount) as revenue
FROM
	lineitem_large_shard_id
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
---------------------------------------------------------------------
 243277.7858
(1 row)

