#!/bin/bash

if [ ! -z "$1" ]; then ITERATIONS=$1; else ITERATIONS=30; fi;
DATABASE=test2

mariadb -e "create database if not exists $DATABASE";
if [ -z $(mariadb $DATABASE -s -e "SHOW TABLES LIKE '%zzrandom'") ]; then
    echo "[+] Creating Table: zzrandom ..."
    mariadb $DATABASE -e "CREATE TABLE zzrandom( group_name CHAR(2), number1 DECIMAL(12, 2), number2 DECIMAL(12, 2), var varchar(1), var2 varchar(100), var3 varchar(100), var4 varchar(100), var5 varchar(100), var6 varchar(100), var7 varchar(100), number3 DECIMAL(12, 2), number4 DECIMAL(12, 2), number5 DECIMAL(12, 2), number6 DECIMAL(12, 2), var8 varchar(1), var9 varchar(100), var10 varchar(100), var11 varchar(100), var12 varchar(100), var13 varchar(100), var14 varchar(100), number7 DECIMAL(12, 2), number8 DECIMAL(12, 2), number9 DECIMAL(12, 2), number10 DECIMAL(12, 2), var15 varchar(1), var16 varchar(100), var17 varchar(100), var18 varchar(100), var19 varchar(100), var20 varchar(100), var21 varchar(100), number11 DECIMAL(12, 2), number12 DECIMAL(12, 2), number13 DECIMAL(12, 2), number14 DECIMAL(12, 2), group_name2 CHAR(2), number15 DECIMAL(12, 2), number16 DECIMAL(12, 2), var22 varchar(1), var23 varchar(100), var24 varchar(100), var25 varchar(100), var26 varchar(100), var27 varchar(100), var28 varchar(100), number17 DECIMAL(12, 2), number18 DECIMAL(12, 2), number19 DECIMAL(12, 2), number20 DECIMAL(12, 2), var29 varchar(1), var30 varchar(100), var32 varchar(100), var33 varchar(100), var34 varchar(100), var35 varchar(100), var36 varchar(100), number21 DECIMAL(12, 2), number22 DECIMAL(12, 2), number23 DECIMAL(12, 2), number24 DECIMAL(12, 2), var37 varchar(1), var38 varchar(100), var39 varchar(100), var40 varchar(100), var42 varchar(100), var43 varchar(100), var44 varchar(100), number25 DECIMAL(12, 2), number26 DECIMAL(12, 2), number27 DECIMAL(12, 2), number28 DECIMAL(12, 2), col73 DECIMAL(12, 2), col74 DECIMAL(12, 2), col75 DECIMAL(12, 2), col76 DECIMAL(12, 2), col77 DECIMAL(12, 2), col78 DECIMAL(12, 2), col79 DECIMAL(12, 2), col80 DECIMAL(12, 2), col81 varchar(200), col82 varchar(200), col83 varchar(200), col84 varchar(200), col85 varchar(200), col86 varchar(200), col87 varchar(200), col88 varchar(200), col89 varchar(200), col90 varchar(200), col91 varchar(200), col92 varchar(200), col93 varchar(200), col94 varchar(200), col95 varchar(200), col96 varchar(200), col97 varchar(200), col98 varchar(200), col99 varchar(200), col100 varchar(200), col101 DECIMAL(12, 2), col102 DECIMAL(12, 2), col103 DECIMAL(12, 2), col104 DECIMAL(12, 2), col105 DECIMAL(12, 2), col106 DECIMAL(12, 2), col107 DECIMAL(12, 2), col108 DECIMAL(12, 2), col109 DECIMAL(12, 2), col110 DECIMAL(12, 2), col111 DECIMAL(12, 2), col112 DECIMAL(12, 2), col113 DECIMAL(12, 2), col114 DECIMAL(12, 2), col115 DECIMAL(12, 2), col116 DECIMAL(12, 2), col117 DECIMAL(12, 2), col118 DECIMAL(12, 2), col119 DECIMAL(12, 2), col120 DECIMAL(12, 2), col121 varchar(100), col122 varchar(100), col123 varchar(100), col124 varchar(100), col125 varchar(100), col126 varchar(100), col127 varchar(100), col128 varchar(100), col129 varchar(100), col130 varchar(100), col131 varchar(100), col132 varchar(100), col133 varchar(100), col134 varchar(100), col135 varchar(100), col136 varchar(100), col137 varchar(100), col138 varchar(100), col139 varchar(100), col140 varchar(100), col141 DECIMAL(12, 2), col142 DECIMAL(12, 2), col143 DECIMAL(12, 2), col144 DECIMAL(12, 2), col145 DECIMAL(12, 2), col146 DECIMAL(12, 2), col147 DECIMAL(12, 2), col148 DECIMAL(12, 2), col149 DECIMAL(12, 2), col150 DECIMAL(12, 2), col151 DECIMAL(12, 2), col152 DECIMAL(12, 2), col153 DECIMAL(12, 2), col154 DECIMAL(12, 2), col155 DECIMAL(12, 2), col156 DECIMAL(12, 2), col157 DECIMAL(12, 2), col158 DECIMAL(12, 2), col159 DECIMAL(12, 2), col160 DECIMAL(12, 2), col161 varchar(100), col162 varchar(100), col163 varchar(100), col164 varchar(100), col165 varchar(100), col166 varchar(100), col167 varchar(100), col168 varchar(100), col169 varchar(100), col170 varchar(100), col171 varchar(100), col172 varchar(100), col173 varchar(100), col174 varchar(100), col175 varchar(100), col176 varchar(100), col177 varchar(100), col178 varchar(100), col179 varchar(100), col180 varchar(100), col181 DECIMAL(12, 2), col182 DECIMAL(12, 2), col183 DECIMAL(12, 2), col184 DECIMAL(12, 2), col185 DECIMAL(12, 2), col186 DECIMAL(12, 2), col187 DECIMAL(12, 2), col188 DECIMAL(12, 2), col189 DECIMAL(12, 2), col190 DECIMAL(12, 2), col191 DECIMAL(12, 2), col192 DECIMAL(12, 2), col193 DECIMAL(12, 2), col194 DECIMAL(12, 2), col195 DECIMAL(12, 2), col196 DECIMAL(12, 2), col197 DECIMAL(12, 2), col198 DECIMAL(12, 2), col199 DECIMAL(12, 2), col200 DECIMAL(12, 2), col201 varchar(250), col202 varchar(250), col203 varchar(250), col204 varchar(250), col205 varchar(250), col206 varchar(250), col207 varchar(250), col208 varchar(250), col209 varchar(250), col210 varchar(250), col211 varchar(250), col212 varchar(250), col213 varchar(250), col214 varchar(250), col215 varchar(250), col216 varchar(250), col217 varchar(250), col218 varchar(250), col219 varchar(250), col220 varchar(250), col221 DECIMAL(12, 2), col222 DECIMAL(12, 2), col223 DECIMAL(12, 2), col224 DECIMAL(12, 2), col225 DECIMAL(12, 2), col226 DECIMAL(12, 2), col227 DECIMAL(12, 2), col228 DECIMAL(12, 2), col229 DECIMAL(12, 2), col230 DECIMAL(12, 2), col231 DECIMAL(12, 2), col232 DECIMAL(12, 2), col233 DECIMAL(12, 2), col234 DECIMAL(12, 2), col235 DECIMAL(12, 2), col236 DECIMAL(12, 2), col237 DECIMAL(12, 2), col238 DECIMAL(12, 2), col239 DECIMAL(12, 2), col240 DECIMAL(12, 2), col241 varchar(250), col242 varchar(250), col243 varchar(250), col244 varchar(250), col245 varchar(250), col246 varchar(250), col247 varchar(250), col248 varchar(250), col249 varchar(250), col250 varchar(250)) ENGINE=COLUMNSTORE;"

    #echo "Inserting into zzrandom"
    #mariadb $DATABASE -s -e "INSERT INTO zzrandom SELECT CAST(ROUND(RAND() * 10, 0) AS CHAR), ROUND(RAND() * 10000, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), CAST(ROUND(RAND() * 10, 0) AS CHAR), ROUND(RAND() * 10000, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,1), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), ROUND(RAND() * 10, 2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2), substring(MD5(RAND()),1,2) FROM seq_1_to_2;"
fi

i=0
echo "Executing $ITERATIONS queries"
while [ $i -lt $ITERATIONS ]; do
    mariadb $DATABASE -e "select * from zzrandom;" &
    ((i++))
done