github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/lightning_tidb_rowid/run.sh (about)

     1  #!/bin/sh
     2  #
     3  # Copyright 2019 PingCAP, Inc.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  # Verify that _tidb_rowid is correctly adjusted.
    17  
    18  set -eu
    19  
    20  for BACKEND in local importer tidb; do
    21    if [ "$BACKEND" = 'local' ]; then
    22        check_cluster_version 4 0 0 'local backend' || continue
    23    fi
    24  
    25    run_sql 'DROP DATABASE IF EXISTS rowid;'
    26    run_lightning -backend $BACKEND
    27    echo 'Import finished'
    28  
    29    # we can't determine the exact `_tidb_row_id` alloc logic, so just skip this check with tidb backend.
    30    if [ "$BACKEND" != 'tidb' ]; then
    31      run_sql 'SELECT count(*), max(id), min(_tidb_rowid), max(_tidb_rowid) FROM rowid.`non_pk_auto_inc`'
    32      check_contains 'count(*): 22'
    33      check_contains 'max(id): 37'
    34      check_contains 'min(_tidb_rowid): 1'
    35      check_contains 'max(_tidb_rowid): 22'
    36      run_sql 'INSERT INTO rowid.`non_pk_auto_inc` (`pk`) VALUES ("?")'
    37      run_sql 'SELECT id > 37, _tidb_rowid > 22 FROM rowid.`non_pk_auto_inc` WHERE `pk` = "?"'
    38      check_contains 'id > 37: 1'
    39      check_contains '_tidb_rowid > 22: 1'
    40    fi
    41  
    42    for table_name in non_pk explicit_tidb_rowid; do
    43        run_sql "SELECT count(*), min(_tidb_rowid), max(_tidb_rowid) FROM rowid.${table_name}"
    44        check_contains 'count(*): 10'
    45        check_contains 'min(_tidb_rowid): 1'
    46        check_contains 'max(_tidb_rowid): 10'
    47        run_sql "SELECT _tidb_rowid FROM rowid.${table_name} WHERE pk = 'five'"
    48        check_contains '_tidb_rowid: 5'
    49        run_sql "INSERT INTO rowid.${table_name} VALUES ('eleven')"
    50        run_sql "SELECT count(*) FROM rowid.${table_name}"
    51        check_contains 'count(*): 11'
    52        run_sql "SELECT count(*) FROM rowid.${table_name} WHERE pk > '!'"
    53        check_contains 'count(*): 11'
    54        run_sql "SELECT _tidb_rowid > 10 FROM rowid.${table_name} WHERE pk = 'eleven'"
    55        check_contains '_tidb_rowid > 10: 1'
    56    done
    57  
    58    run_sql 'SELECT count(*), min(_tidb_rowid), max(_tidb_rowid) FROM rowid.pre_rebase'
    59    check_contains 'count(*): 1'
    60    check_contains 'min(_tidb_rowid): 70000'
    61    check_contains 'max(_tidb_rowid): 70000'
    62    run_sql 'INSERT INTO rowid.pre_rebase VALUES ("?")'
    63    run_sql 'SELECT _tidb_rowid > 70000 FROM rowid.pre_rebase WHERE pk = "?"'
    64    check_contains '_tidb_rowid > 70000: 1'
    65  
    66    run_sql 'SELECT count(*) FROM rowid.specific_auto_inc'
    67    check_contains 'count(*): 5'
    68    run_sql 'INSERT INTO rowid.specific_auto_inc (a) VALUES ("ffffff"), ("gggggg")'
    69    run_sql 'SELECT _tidb_rowid > 80000, b > 80000 FROM rowid.specific_auto_inc WHERE a = "ffffff"'
    70    check_contains '_tidb_rowid > 80000: 1'
    71    check_contains 'b > 80000: 1'
    72    run_sql 'SELECT _tidb_rowid > 80000, b > 80000 FROM rowid.specific_auto_inc WHERE a = "gggggg"'
    73    check_contains '_tidb_rowid > 80000: 1'
    74    check_contains 'b > 80000: 1'
    75  done