#  WL#5096
#  
#  Description 
#  ===========
#
#  This test case covers Requirements for different index structures
#  on both master and slave.
#
#  Usage
#  =====
#
#  Before including this file the following variables should be set:
#    * $server_1_engine
#    * $server_2_engine
#    * $server_3_engine
#
#  Example:
#
#     -- let $server_1_engine= Falcon
#     -- let $server_2_engine= MyISAM
#     -- let $server_3_engine= InnoDB
#
#     -- source extra/rpl_tests/rpl_row_img_diff_indexes.test
# 

-- connection server_1

-- source include/rpl_sync.inc

-- connection server_1

-- let $diff_table=test.t

let $i= 16;
while($i)
{
  -- connection server_1
  SET SQL_LOG_BIN=0;

  -- connection server_2
  SET SQL_LOG_BIN=0;

  -- connection server_3
  SET SQL_LOG_BIN=0;


  if ($i == 1) {
    -- echo ### Different PKs on master and first slave
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c1)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c2(512))) engine= $server_2_engine;
    -- connection server_3 
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c1)) engine= $server_3_engine;
  }
  if ($i == 2)
  { 
    -- echo ### Different PKs on master and first slave (which has unique NOT NULL key instead of PK)
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, primary key(c1)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, unique key(c2(512))) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, primary key(c1)) engine= $server_3_engine;
  }
  if ($i == 3)
  { 
    -- echo ### Master with PK and first slave with KEY only
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c1)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c3)) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c2(512))) engine= $server_3_engine;
  }
  if ($i == 4)
  { 
    -- echo ### Master with PK and no keys on the slaves
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c3)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_3_engine;
  }
  if ($i == 5) {
    -- echo ### Master with UK NOT NULL and slaves with PK on different fields
    -- connection server_1
    --eval CREATE TABLE t (c1 int NOT NULL, c2 blob, c3 int, unique key(c1)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c2(512))) engine= $server_2_engine;
    -- connection server_3 
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c1)) engine= $server_3_engine;
  }
  if ($i == 6)
  { 
    -- echo ### Master with UK NOT NULL, first slave with UK NOT NULL on different field
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, unique key(c1)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, unique key(c2(512))) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, primary key(c1)) engine= $server_3_engine;
  }
  if ($i == 7)
  { 
    -- echo ### Master with UK NULLABLE, first slave with K on different field second slave with key on yet another different field
      
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, unique key(c1)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c3)) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c2(512))) engine= $server_3_engine;
  }
  if ($i == 8)
  { 
    -- echo ### Master with UK NULLABLE, slaves with no keys
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, unique key(c3)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_3_engine;
  }
  if ($i == 9) {
    -- echo ### Master with Key, slaves with PKs on different fields
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c1)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c2(512))) engine= $server_2_engine;
    -- connection server_3 
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c1)) engine= $server_3_engine;
  }
  if ($i == 10)
  { 
    -- echo ### Master with Key, slaves with PKs on different fields (first slave has UK NOT NULL)
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, key(c1)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, unique key(c2(512))) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, primary key(c1)) engine= $server_3_engine;
  }
  if ($i == 11)
  { 
    -- echo ### Master with Key, first slave with key on different field and second slave with key on yet another different field.
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c1)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c3)) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c2(512))) engine= $server_3_engine;
  }
  if ($i == 12)
  { 
    -- echo ### Master with Key, slaves with no keys
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c3)) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_3_engine;
  }
  if ($i == 13) {
    -- echo ### Master with no key, slaves with PKs on different fields
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c2(512))) engine= $server_2_engine;
    -- connection server_3 
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, primary key(c1)) engine= $server_3_engine;
  }
  if ($i == 14)
  { 
    -- echo ### Master with no key, slaves with PKs on different fields (first slave with UK NOT NULL, second with PK)
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, unique key(c2(512))) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob NOT NULL, c3 int, primary key(c1)) engine= $server_3_engine;
  }
  if ($i == 15)
  { 
    -- echo ### Master with no key, slaves with keys
    -- connection server_1
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_1_engine;
    -- connection server_2
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c3)) engine= $server_2_engine;
    -- connection server_3
    --eval CREATE TABLE t (c1 int, c2 blob, c3 int, key(c2(512))) engine= $server_3_engine;
  }
  if ($i == 16)
  { 
    -- echo ### Master with no keys slaves with no keys as well
    -- connection server_1
    -- eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_1_engine
    -- connection server_2
    -- eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_2_engine
    -- connection server_3
    -- eval CREATE TABLE t (c1 int, c2 blob, c3 int) engine= $server_3_engine
  }

  -- connection server_1
  SET SQL_LOG_BIN=1;

  -- connection server_2
  SET SQL_LOG_BIN=1;

  -- connection server_3
  SET SQL_LOG_BIN=1;

  -- connection server_1

  -- let $blob1= "a"
  -- let $blob2= "b"
  -- let $blob3= "c"

  -- eval INSERT INTO t VALUES (1, $blob1, 10)
  -- eval INSERT INTO t VALUES (2, $blob2, 20)
  -- eval INSERT INTO t VALUES (3, $blob3, 30)
  
  -- source include/rpl_sync.inc

  -- connection server_1
  -- eval UPDATE t SET c1=10 WHERE c2=$blob1
  -- eval UPDATE t SET c1=20 WHERE c1=2
  -- eval UPDATE t SET c1=30 WHERE c3=30
  -- eval UPDATE t SET c3=40 WHERE c1=30

  -- source include/rpl_sync.inc

  -- let $diff_tables= server_1:$diff_table, server_2:$diff_table, server_3:$diff_table
  -- source include/diff_tables.inc

  -- connection server_1
  -- eval DELETE FROM t WHERE c2=$blob1
  -- eval DELETE FROM t WHERE c1=20
  -- eval DELETE FROM t

  -- source include/rpl_sync.inc

  -- let $diff_tables= server_1:$diff_table, server_2:$diff_table, server_3:$diff_table
  -- source include/diff_tables.inc

  -- connection server_1

  DROP TABLE t;

  -- source include/rpl_sync.inc

  dec $i;
}
