|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +bash -n "$0" | exit 1 |
| 4 | +source ${TESTSROOTDIR}/tools/runit_common.sh |
| 5 | + |
| 6 | +DBNAME=$1 |
| 7 | +TESTNAME="sp_perf" |
| 8 | +output="$TESTNAME.out" |
| 9 | +expected="$TESTNAME.exp" |
| 10 | +tier="default" |
| 11 | +if [ -f $output ] ; then |
| 12 | + rm -f $output |
| 13 | +fi |
| 14 | + |
| 15 | +if [[ "x${DBNAME}" == "x" ]] ; then |
| 16 | + echo "need a DB name" |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +longoremptystringTest() { |
| 21 | + |
| 22 | + |
| 23 | +sp=$(cat << 'EOF' |
| 24 | +CREATE PROCEDURE foo VERSION 'test' { |
| 25 | +local function main(x, input) |
| 26 | + db:setmaxinstructions(10000000) |
| 27 | + local t = {} |
| 28 | + local s = nil |
| 29 | + if input ~= nil then |
| 30 | + s = input |
| 31 | + else |
| 32 | + s = string.format("%s%s", string.rep('a,', 999999), 'a') |
| 33 | + end |
| 34 | + if x == 'cstring' then s = db:cast(s, 'cstring') end |
| 35 | + local start = db:now() |
| 36 | + for str in string.gmatch(s, "([^,]+)") do table.insert(t, str) end |
| 37 | + db:column_name("count", 1) db:column_name("time", 2) db:column_name("type", 3) |
| 38 | + db:emit({count = #t, time = db:now() - start, type = type(s)}) |
| 39 | +end |
| 40 | +} |
| 41 | +EOF |
| 42 | +) |
| 43 | +${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "$sp" |
| 44 | +time ${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "exec procedure foo()" |
| 45 | +time ${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "exec procedure foo('cstring')" |
| 46 | +time ${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "exec procedure foo('cstring', 'spookytext')" |
| 47 | +time ${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "exec procedure foo('cstring', '')" |
| 48 | +} |
| 49 | + |
| 50 | + |
| 51 | +bindparamTest() { |
| 52 | + |
| 53 | +$CDB2SQL_EXE ${CDB2_OPTIONS} $DBNAME $tier - <<EOF |
| 54 | +drop table if exists bindt |
| 55 | +create table bindt { |
| 56 | +schema { |
| 57 | + cstring i[32] null=yes |
| 58 | + cstring j[32] null=yes |
| 59 | +}}\$\$ |
| 60 | +EOF |
| 61 | + |
| 62 | +sp_bind_pos=$(cat << 'EOF' |
| 63 | +CREATE PROCEDURE bind_sp VERSION 'test' { |
| 64 | +local function main() |
| 65 | + local t, r |
| 66 | + t = db:prepare("INSERT INTO bindt(i, j) values(?,?)") |
| 67 | + t:bind(1, "1") -- bind by pos |
| 68 | + t:bind(2, "") |
| 69 | + t:exec() |
| 70 | +end |
| 71 | +} |
| 72 | +EOF |
| 73 | +) |
| 74 | + |
| 75 | +sp_bind_name=$(cat << 'EOF' |
| 76 | +CREATE PROCEDURE bind_sp_named VERSION 'test' { |
| 77 | +local function main() |
| 78 | + local t, r, a, b |
| 79 | + t = db:prepare("INSERT INTO bindt(i, j) values(@a, @b)") |
| 80 | + t:bind("a", "5") -- bind by name |
| 81 | + t:bind("b", "6") |
| 82 | + t:exec() |
| 83 | +end |
| 84 | +} |
| 85 | +EOF |
| 86 | +) |
| 87 | + |
| 88 | +${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "$sp_bind_pos" |
| 89 | +${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "exec procedure bind_sp()" |
| 90 | +${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "SELECT i, j FROM bindt" |
| 91 | +${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "$sp_bind_name" |
| 92 | +${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "exec procedure bind_sp_named()" |
| 93 | +${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier "SELECT i, j FROM bindt" |
| 94 | +${CDB2SQL_EXE} -r 1 ${CDB2_OPTIONS} $DBNAME $tier - <<EOF |
| 95 | +INSERT INTO bindt (i, j) VALUES ('5', NULL) |
| 96 | +INSERT INTO bindt (i, j) VALUES ('', '6') |
| 97 | +EOF |
| 98 | + |
| 99 | +} |
| 100 | + |
| 101 | +checkdiff() { |
| 102 | +if [ -f "$1" ]; then |
| 103 | + if ! diff -w $2 $1 > /dev/null 2>&1 ; then |
| 104 | + echo "diff:" |
| 105 | + diff -w $2 $1 |
| 106 | + failexit "output $1 diff from expected $2" |
| 107 | + else |
| 108 | + echo "PASSED!" |
| 109 | + fi |
| 110 | +else |
| 111 | + failexit "ERR: No expected output file ($2) found for runit" |
| 112 | +fi |
| 113 | + |
| 114 | +} |
| 115 | + |
| 116 | +longoremptystringTest |
| 117 | + |
| 118 | +bindparamTest >> "$output" 2>&1 |
| 119 | +checkdiff "$output" "$expected" |
| 120 | + |
| 121 | +${TESTSROOTDIR}/tools/compare_results.sh -s -d $DBNAME |
| 122 | +[ $? -eq 0 ] || exit 1 |
| 123 | + |
| 124 | +${TESTSBUILDDIR}/sp $DBNAME $tier >> "sp_bind.out" 2>&1 |
| 125 | +[ $? -eq 0 ] || exit 1 |
| 126 | + |
| 127 | +checkdiff "sp_bind.out" "sp_bind.exp" |
| 128 | + |
| 129 | +echo "Testcase passed." |
| 130 | + |
| 131 | +exit 0 |
| 132 | + |
| 133 | + |
0 commit comments