import file=ycsb_schema
----

# --------------------------------------------------
# Workload A: Update heavy
#
# This workload has a mix of 50/50 reads and writes. Application example:
# a session store recording recent actions.
# --------------------------------------------------

# 50% of the workload.
opt
SELECT * FROM usertable WHERE ycsb_key = 'user123'
----
scan usertable
 ├── columns: ycsb_key:1!null field0:2 field1:3 field2:4 field3:5 field4:6 field5:7 field6:8 field7:9 field8:10 field9:11
 ├── constraint: /1: [/'user123' - /'user123']
 ├── cardinality: [0 - 1]
 ├── key: ()
 └── fd: ()-->(1-11)

# 50% of the workload.
opt
UPDATE usertable SET field5 = 'field5data' WHERE ycsb_key = 'user123'
----
update usertable
 ├── columns: <none>
 ├── fetch columns: ycsb_key:14 field5:20
 ├── update-mapping:
 │    └── field5_new:27 => field5:7
 ├── cardinality: [0 - 0]
 ├── volatile, mutations
 └── project
      ├── columns: field5_new:27!null ycsb_key:14!null field5:20
      ├── cardinality: [0 - 1]
      ├── key: ()
      ├── fd: ()-->(14,20,27)
      ├── scan usertable
      │    ├── columns: ycsb_key:14!null field5:20
      │    ├── constraint: /14: [/'user123' - /'user123']
      │    ├── flags: avoid-full-scan
      │    ├── cardinality: [0 - 1]
      │    ├── key: ()
      │    └── fd: ()-->(14,20)
      └── projections
           └── 'field5data' [as=field5_new:27]

# --------------------------------------------------
# Workload B: Read mostly
#
# This workload has a 95/5 reads/write mix. Application example: photo
# tagging; add a tag is an update, but most operations are to read tags.
# --------------------------------------------------

# NOTE: same statements as Workload A, just a different mix. 95% of the
# workload is the SELECT statement and 5% of the workload is the UPDATE
# statement.

# --------------------------------------------------
# Workload C: Read only
#
# This workload is 100% read. Application example: user profile cache,
# where profiles are constructed elsewhere (e.g., Hadoop).
# --------------------------------------------------

# NOTE: consists entirely of the SELECT statement from workload A.

# --------------------------------------------------
# Workload D: Read latest
#
# In this workload, new records are inserted, and the most recently
# inserted records are the most popular. Application example: user
# status updates; people want to read the latest.
# --------------------------------------------------

# NOTE: 95% of the workload is the SELECT statement from workload A.

# 5% of the workload.
opt
INSERT INTO usertable VALUES (
    'user123',
    'field0data',
    'field1data',
    'field2data',
    'field3data',
    'field4data',
    'field5data',
    'field6data',
    'field7data',
    'field8data',
    'field9data'
)
----
insert usertable
 ├── columns: <none>
 ├── insert-mapping:
 │    ├── ycsb_key_cast:25 => ycsb_key:1
 │    ├── column2:15 => field0:2
 │    ├── column3:16 => field1:3
 │    ├── column4:17 => field2:4
 │    ├── column5:18 => field3:5
 │    ├── column6:19 => field4:6
 │    ├── column7:20 => field5:7
 │    ├── column8:21 => field6:8
 │    ├── column9:22 => field7:9
 │    ├── column10:23 => field8:10
 │    └── column11:24 => field9:11
 ├── cardinality: [0 - 0]
 ├── volatile, mutations
 └── values
      ├── columns: column2:15!null column3:16!null column4:17!null column5:18!null column6:19!null column7:20!null column8:21!null column9:22!null column10:23!null column11:24!null ycsb_key_cast:25!null
      ├── cardinality: [1 - 1]
      ├── key: ()
      ├── fd: ()-->(15-25)
      └── ('field0data', 'field1data', 'field2data', 'field3data', 'field4data', 'field5data', 'field6data', 'field7data', 'field8data', 'field9data', 'user123')

# --------------------------------------------------
# Workload E: Short ranges
#
# In this workload, short ranges of records are queried, instead of
# individual records. Application example: threaded conversations,
# where each scan is for the posts in a given thread (assumed to be
# clustered by thread id).
# --------------------------------------------------

# NOTE: 5% of the workload is the INSERT statement from workload D.

# 95% of the workload.
opt
SELECT * FROM usertable WHERE ycsb_key >= 'user123' LIMIT 321
----
scan usertable
 ├── columns: ycsb_key:1!null field0:2 field1:3 field2:4 field3:5 field4:6 field5:7 field6:8 field7:9 field8:10 field9:11
 ├── constraint: /1: [/'user123' - ]
 ├── limit: 321
 ├── key: (1)
 └── fd: (1)-->(2-11)

# --------------------------------------------------
# Workload F: Read-modify-write
#
# In this workload, the client will read a record, modify it, and write
# back the changes. Application example: user database, where user
# records are read and modified by the user or to record user activity.
# --------------------------------------------------

# NOTE: 50% of the workload is the SELECT statement from workload A.

# NOTE: the following two statements are run together in a transaction
# to perform a read-modify-write operation. This makes up 50% of the
# workload.

opt
SELECT field5 FROM usertable WHERE ycsb_key = 'user123'
----
project
 ├── columns: field5:7
 ├── cardinality: [0 - 1]
 ├── key: ()
 ├── fd: ()-->(7)
 └── scan usertable
      ├── columns: ycsb_key:1!null field5:7
      ├── constraint: /1: [/'user123' - /'user123']
      ├── cardinality: [0 - 1]
      ├── key: ()
      └── fd: ()-->(1,7)

opt
UPDATE usertable SET field5 = 'field5data' WHERE ycsb_key = 'user123'
----
update usertable
 ├── columns: <none>
 ├── fetch columns: ycsb_key:14 field5:20
 ├── update-mapping:
 │    └── field5_new:27 => field5:7
 ├── cardinality: [0 - 0]
 ├── volatile, mutations
 └── project
      ├── columns: field5_new:27!null ycsb_key:14!null field5:20
      ├── cardinality: [0 - 1]
      ├── key: ()
      ├── fd: ()-->(14,20,27)
      ├── scan usertable
      │    ├── columns: ycsb_key:14!null field5:20
      │    ├── constraint: /14: [/'user123' - /'user123']
      │    ├── flags: avoid-full-scan
      │    ├── cardinality: [0 - 1]
      │    ├── key: ()
      │    └── fd: ()-->(14,20)
      └── projections
           └── 'field5data' [as=field5_new:27]
