github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/tests/br_table_partition/prepare.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  set -eu
    17  
    18  ROW_COUNT=100
    19  CONCURRENCY=8
    20  
    21  TABLE_COLUMNS='c1 INT, c2 CHAR(255), c3 CHAR(255), c4 CHAR(255), c5 CHAR(255)'
    22  
    23  insertRecords() {
    24      for i in $(seq $2 $3); do
    25          run_sql "INSERT INTO $1 VALUES (\
    26              $i, \
    27              REPEAT(' ', 255), \
    28              REPEAT(' ', 255), \
    29              REPEAT(' ', 255), \
    30              REPEAT(' ', 255)\
    31          );"
    32      done
    33  }
    34  
    35  createTable() {
    36      run_sql "CREATE TABLE IF NOT EXISTS $DB.$TABLE$1 ($TABLE_COLUMNS) \
    37          PARTITION BY RANGE(c1) ( \
    38          PARTITION p0 VALUES LESS THAN (0), \
    39          PARTITION p1 VALUES LESS THAN ($(expr $ROW_COUNT / 2)) \
    40      );"
    41      run_sql "ALTER TABLE $DB.$TABLE$1 \
    42        ADD PARTITION (PARTITION p2 VALUES LESS THAN MAXVALUE);"
    43  }
    44  
    45  echo "load database $DB"
    46  run_sql "CREATE DATABASE IF NOT EXISTS $DB;"
    47  for i in $(seq $TABLE_COUNT); do
    48    createTable "${i}" &
    49  done
    50  
    51  run_sql "CREATE TABLE IF NOT EXISTS $DB.${TABLE}_Hash ($TABLE_COLUMNS) PARTITION BY HASH(c1) PARTITIONS 5;" &
    52  # `tidb_enable_list_partition` currently only support session level variable, so we must put it in the create table sql
    53  run_sql "set @@session.tidb_enable_list_partition = 'ON'; CREATE TABLE IF NOT EXISTS $DB.${TABLE}_List ($TABLE_COLUMNS) PARTITION BY LIST(c1) (\
    54      PARTITION p0 VALUES IN (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97),
    55      PARTITION p1 VALUES IN (1, 4, 9, 16, 25, 36, 49, 64, 81, 100),
    56      PARTITION p2 VALUES IN (8, 18, 20, 24, 26, 30, 32, 44, 46, 50, 51, 55, 56, 58, 60, 75, 78, 80, 84, 85, 88, 90),
    57      PARTITION p3 VALUES IN (6, 12, 15, 22, 28, 33, 34, 38, 42, 54, 62, 63, 68, 69, 70, 74, 82, 91, 93, 94, 96, 98),
    58      PARTITION p4 VALUES IN (10, 14, 21, 27, 35, 39, 40, 45, 48, 52, 57, 65, 66, 72, 76, 77, 86, 87, 92, 95, 99)
    59  )" &
    60  
    61  wait
    62  
    63  for i in $(seq $TABLE_COUNT); do
    64      for j in $(seq $CONCURRENCY); do
    65          insertRecords $DB.$TABLE${i} $(expr $ROW_COUNT / $CONCURRENCY \* $(expr $j - 1) + 1) $(expr $ROW_COUNT / $CONCURRENCY \* $j) &
    66      done
    67      insertRecords $DB.${TABLE}_Hash 1 $ROW_COUNT &
    68      insertRecords $DB.${TABLE}_List 1 $ROW_COUNT &
    69  done
    70  wait