Commit 67087e2a authored by mronstrom@mysql.com's avatar mronstrom@mysql.com

Patch for push of wl1354 Partitioning

parent 8b90390e
......@@ -128,8 +128,9 @@ AC_DEFUN([MYSQL_CHECK_NDBCLUSTER], [
ndb_mgmclient_libs=
case "$ndbcluster" in
yes )
AC_MSG_RESULT([Using NDB Cluster])
AC_MSG_RESULT([Using NDB Cluster and Partitioning])
AC_DEFINE([HAVE_NDBCLUSTER_DB], [1], [Using Ndb Cluster DB])
AC_DEFINE([HAVE_PARTITION_DB], [1], [Builds Partition DB])
have_ndbcluster="yes"
ndbcluster_includes="-I\$(top_builddir)/storage/ndb/include -I\$(top_builddir)/storage/ndb/include/ndbapi"
ndbcluster_libs="\$(top_builddir)/storage/ndb/src/.libs/libndbclient.a"
......
dnl ---------------------------------------------------------------------------
dnl Macro: MYSQL_CHECK_PARTITIONDB
dnl Sets HAVE_PARTITION_DB if --with-partition is used
dnl ---------------------------------------------------------------------------
AC_DEFUN([MYSQL_CHECK_PARTITIONDB], [
AC_ARG_WITH([partition],
[
--with-partition
Enable the Partition Storage Engine],
[partitiondb="$withval"],
[partitiondb=no])
AC_MSG_CHECKING([for partition])
case "$partitiondb" in
yes )
AC_DEFINE([HAVE_PARTITION_DB], [1], [Builds Partition DB])
AC_MSG_RESULT([yes])
[partitiondb=yes]
;;
* )
AC_MSG_RESULT([no])
[partitiondb=no]
;;
esac
])
dnl ---------------------------------------------------------------------------
dnl END OF MYSQL_CHECK_PARTITION SECTION
dnl ---------------------------------------------------------------------------
......@@ -2437,6 +2437,7 @@ MYSQL_CHECK_CSVDB
MYSQL_CHECK_BLACKHOLEDB
MYSQL_CHECK_NDBCLUSTER
MYSQL_CHECK_FEDERATED
MYSQL_CHECK_PARTITIONDB
# If we have threads generate some library functions and test programs
sql_server_dirs=
......
......@@ -388,6 +388,7 @@ enum data_file_type {
#define EQ_RANGE 32
#define NULL_RANGE 64
#define GEOM_FLAG 128
#define SKIP_RANGE 256
typedef struct st_key_range
{
......
......@@ -101,6 +101,94 @@
#define unlikely(x) __builtin_expect((x),0)
/*
The macros below are useful in optimising places where it has been
discovered that cache misses stall the process and where a prefetch
of the cache line can improve matters. This is available in GCC 3.1.1
and later versions.
PREFETCH_READ says that addr is going to be used for reading and that
it is to be kept in caches if possible for a while
PREFETCH_WRITE also says that the item to be cached is likely to be
updated.
The *LOCALITY scripts are also available for experimentation purposes
mostly and should only be used if they are verified to improve matters.
For more input see GCC manual (available in GCC 3.1.1 and later)
*/
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
#define PREFETCH_READ(addr) __builtin_prefetch(addr, 0, 3)
#define PREFETCH_WRITE(addr) \
__builtin_prefetch(addr, 1, 3)
#define PREFETCH_READ_LOCALITY(addr, locality) \
__builtin_prefetch(addr, 0, locality)
#define PREFETCH_WRITE_LOCALITY(addr, locality) \
__builtin_prefetch(addr, 1, locality)
#else
#define PREFETCH_READ(addr)
#define PREFETCH_READ_LOCALITY(addr, locality)
#define PREFETCH_WRITE(addr)
#define PREFETCH_WRITE_LOCALITY(addr, locality)
#endif
/*
The following macro is used to ensure that code often used in most
SQL statements and definitely for parts of the SQL processing are
kept in a code segment by itself. This has the advantage that the
risk of common code being overlapping in caches of the CPU is less.
This can be a cause of big performance problems.
Routines should be put in this category with care and when they are
put there one should also strive to make as much of the error handling
as possible (or uncommon code of the routine) to execute in a
separate method to avoid moving to much code to this code segment.
It is very easy to use, simply add HOT_METHOD at the end of the
function declaration.
For more input see GCC manual (available in GCC 2.95 and later)
*/
#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
#define HOT_METHOD \
__attribute__ ((section ("hot_code_section")))
#else
#define HOT_METHOD
#endif
/*
The following macro is used to ensure that popular global variables
are located next to each other to avoid that they contend for the
same cache lines.
It is very easy to use, simply add HOT_DATA at the end of the declaration
of the variable, the variable must be initialised because of the way
that linker works so a declaration using HOT_DATA should look like:
uint global_hot_data HOT_DATA = 0;
For more input see GCC manual (available in GCC 2.95 and later)
*/
#if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR > 94)
#define HOT_DATA \
__attribute__ ((section ("hot_data_section")))
#else
#define HOT_DATA
#endif
/*
The following macros are used to control inlining a bit more than
usual. These macros are used to ensure that inlining always or
never occurs (independent of compilation mode).
For more input see GCC manual (available in GCC 3.1.1 and later)
*/
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR > 10)
#define ALWAYS_INLINE __attribute__ ((always_inline))
#define NEVER_INLINE __attribute__ ((noinline))
#else
#define ALWAYS_INLINE
#define NEVER_INLINE
#endif
/* Fix problem with S_ISLNK() on Linux */
#if defined(TARGET_OS_LINUX)
#undef _GNU_SOURCE
......
......@@ -88,6 +88,8 @@ enum enum_server_command
#define GROUP_FLAG 32768 /* Intern: Group field */
#define UNIQUE_FLAG 65536 /* Intern: Used by sql_yacc */
#define BINCMP_FLAG 131072 /* Intern: Used by sql_yacc */
#define GET_FIXED_FIELDS_FLAG (1 << 18) /* Used to get fields in item tree */
#define FIELD_IN_PART_FUNC_FLAG (1 << 19)/* Field part of partition func */
#define REFRESH_GRANT 1 /* Refresh grant tables */
#define REFRESH_LOG 2 /* Start on new log file */
......
......@@ -41,6 +41,9 @@ typedef struct st_queue {
#define queue_element(queue,index) ((queue)->root[index+1])
#define queue_end(queue) ((queue)->root[(queue)->elements])
#define queue_replaced(queue) _downheap(queue,1)
#define queue_set_cmp_arg(queue, set_arg) (queue)->first_cmp_arg= set_arg
#define queue_set_max_at_top(queue, set_arg) \
(queue)->max_at_top= set_arg ? (-1 ^ 1) : 0
typedef int (*queue_compare)(void *,byte *, byte *);
int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key,
......
-- require r/have_partition.require
disable_query_log;
show variables like "have_partition_engine";
enable_query_log;
Variable_name Value
have_partition_engine YES
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a int, b int, c int, d int, PRIMARY KEY(a,b,c))
ENGINE = NDB
PARTITION BY KEY (a,b);
insert into t1 values (1,1,1,1);
select * from t1;
a b c d
1 1 1 1
update t1 set d = 2 where a = 1 and b = 1 and c = 1;
select * from t1;
a b c d
1 1 1 2
delete from t1;
select * from t1;
a b c d
drop table t1;
CREATE TABLE t1 (a int, b int, c int, d int, PRIMARY KEY(a,b))
ENGINE = NDB
PARTITION BY KEY (c);
ERROR HY000: A PRIMARY KEY need to include all fields in the partition function
CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY(a,b))
ENGINE = NDB
PARTITION BY KEY (a);
insert into t1 values
(1,1,3),(1,2,3),(1,3,3),(1,4,3),(1,5,3),(1,6,3),
(1,7,3),(1,8,3),(1,9,3),(1,10,3),(1,11,3),(1,12,3);
select * from t1 order by b;
a b c
1 1 3
1 2 3
1 3 3
1 4 3
1 5 3
1 6 3
1 7 3
1 8 3
1 9 3
1 10 3
1 11 3
1 12 3
DROP TABLE t1;
CREATE TABLE t1 (a INT, b CHAR(10) COLLATE latin1_bin, c INT, d INT,
PRIMARY KEY USING HASH (a,b,c))
ENGINE=NDB
DEFAULT CHARSET=latin1
PARTITION BY KEY (b);
insert into t1 values (1,"a",1,1),(2,"a",1,1),(3,"a",1,1);
-- t1 --
Fragment type: 5
K Value: 6
Min load factor: 78
Max load factor: 80
Temporary table: no
Number of attributes: 4
Number of primary keys: 3
Length of frm data: 301
TableStatus: Retrieved
-- Attributes --
a Int PRIMARY KEY
b Char(10;latin1_bin) PRIMARY KEY DISTRIBUTION KEY
c Int PRIMARY KEY
d Int NULL
-- Indexes --
PRIMARY KEY(a, b, c) - UniqueHashIndex
NDBT_ProgramExit: 0 - OK
DROP TABLE t1;
drop table if exists t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b),
index (a))
engine = ndb
partition by range (a)
partitions 3
(partition x1 values less than (5),
partition x2 values less than (10),
partition x3 values less than (20));
INSERT into t1 values (1, 1, 1);
INSERT into t1 values (6, 1, 1);
INSERT into t1 values (10, 1, 1);
INSERT into t1 values (15, 1, 1);
select * from t1 order by a;
a b c
1 1 1
6 1 1
10 1 1
15 1 1
select * from t1 where a=1 order by a;
a b c
1 1 1
select * from t1 where a=15 and b=1 order by a;
a b c
15 1 1
select * from t1 where a=21 and b=1 order by a;
a b c
select * from t1 where a=21 order by a;
a b c
select * from t1 where a in (1,6,10,21) order by a;
a b c
1 1 1
6 1 1
10 1 1
select * from t1 where b=1 and a in (1,6,10,21) order by a;
a b c
1 1 1
6 1 1
10 1 1
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(b),
unique (a))
engine = ndb
partition by range (b)
partitions 3
(partition x1 values less than (5),
partition x2 values less than (10),
partition x3 values less than (20));
INSERT into t1 values (1, 1, 1);
INSERT into t1 values (2, 6, 1);
INSERT into t1 values (3, 10, 1);
INSERT into t1 values (4, 15, 1);
select * from t1 order by a;
a b c
1 1 1
2 6 1
3 10 1
4 15 1
UPDATE t1 set a = 5 WHERE b = 15;
select * from t1 order by a;
a b c
1 1 1
2 6 1
3 10 1
5 15 1
UPDATE t1 set a = 6 WHERE a = 5;
select * from t1 order by a;
a b c
1 1 1
2 6 1
3 10 1
6 15 1
select * from t1 where b=1 order by b;
a b c
1 1 1
select * from t1 where b=15 and a=1 order by b;
a b c
select * from t1 where b=21 and a=1 order by b;
a b c
select * from t1 where b=21 order by b;
a b c
select * from t1 where b in (1,6,10,21) order by b;
a b c
1 1 1
2 6 1
3 10 1
select * from t1 where a in (1,2,5,6) order by b;
a b c
1 1 1
2 6 1
6 15 1
select * from t1 where a=1 and b in (1,6,10,21) order by b;
a b c
1 1 1
DELETE from t1 WHERE b = 6;
DELETE from t1 WHERE a = 6;
drop table t1;
This diff is collapsed.
drop table if exists t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (a + 2)
partitions 3
(partition x1 tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
insert into t1 values (1,1,1);
insert into t1 values (2,1,1);
insert into t1 values (3,1,1);
insert into t1 values (4,1,1);
insert into t1 values (5,1,1);
select * from t1;
a b c
1 1 1
4 1 1
2 1 1
5 1 1
3 1 1
update t1 set c=3 where b=1;
select * from t1;
a b c
1 1 3
4 1 3
2 1 3
5 1 3
3 1 3
select b from t1 where a=3;
b
1
select b,c from t1 where a=1 AND b=1;
b c
1 3
delete from t1 where a=1;
delete from t1 where c=3;
select * from t1;
a b c
ALTER TABLE t1
partition by hash (a + 3)
partitions 3
(partition x1 tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
select * from t1;
a b c
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (a)
(partition x1);
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a)
(partition x1);
drop table t1;
drop table if exists t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null)
partition by list(a)
partitions 2
(partition x123 values in (1,5,6),
partition x234 values in (4,7,8));
INSERT into t1 VALUES (1,1,1);
INSERT into t1 VALUES (2,1,1);
ERROR HY000: Got error 1 from storage engine
INSERT into t1 VALUES (3,1,1);
ERROR HY000: Got error 1 from storage engine
INSERT into t1 VALUES (4,1,1);
INSERT into t1 VALUES (5,1,1);
INSERT into t1 VALUES (6,1,1);
INSERT into t1 VALUES (7,1,1);
INSERT into t1 VALUES (8,1,1);
INSERT into t1 VALUES (9,1,1);
ERROR HY000: Got error 1 from storage engine
INSERT into t1 VALUES (1,2,1);
INSERT into t1 VALUES (1,3,1);
INSERT into t1 VALUES (1,4,1);
INSERT into t1 VALUES (7,2,1);
INSERT into t1 VALUES (7,3,1);
INSERT into t1 VALUES (7,4,1);
SELECT * from t1;
a b c
1 1 1
5 1 1
6 1 1
1 2 1
1 3 1
1 4 1
4 1 1
7 1 1
8 1 1
7 2 1
7 3 1
7 4 1
SELECT * from t1 WHERE a=1;
a b c
1 1 1
1 2 1
1 3 1
1 4 1
SELECT * from t1 WHERE a=7;
a b c
7 1 1
7 2 1
7 3 1
7 4 1
SELECT * from t1 WHERE b=2;
a b c
1 2 1
7 2 1
UPDATE t1 SET a=8 WHERE a=7 AND b=3;
SELECT * from t1;
a b c
1 1 1
5 1 1
6 1 1
1 2 1
1 3 1
1 4 1
4 1 1
7 1 1
8 1 1
7 2 1
8 3 1
7 4 1
UPDATE t1 SET a=8 WHERE a=5 AND b=1;
SELECT * from t1;
a b c
1 1 1
6 1 1
1 2 1
1 3 1
1 4 1
4 1 1
7 1 1
8 1 1
7 2 1
8 3 1
7 4 1
8 1 1
DELETE from t1 WHERE a=8;
SELECT * from t1;
a b c
1 1 1
6 1 1
1 2 1
1 3 1
1 4 1
4 1 1
7 1 1
7 2 1
7 4 1
DELETE from t1 WHERE a=2;
SELECT * from t1;
a b c
1 1 1
6 1 1
1 2 1
1 3 1
1 4 1
4 1 1
7 1 1
7 2 1
7 4 1
DELETE from t1 WHERE a=5 OR a=6;
SELECT * from t1;
a b c
1 1 1
1 2 1
1 3 1
1 4 1
4 1 1
7 1 1
7 2 1
7 4 1
ALTER TABLE t1
partition by list(a)
partitions 2
(partition x123 values in (1,5,6),
partition x234 values in (4,7,8));
SELECT * from t1;
a b c
1 1 1
1 2 1
1 3 1
1 4 1
4 1 1
7 1 1
7 2 1
7 4 1
INSERT into t1 VALUES (6,2,1);
INSERT into t1 VALUES (2,2,1);
ERROR HY000: Got error 1 from storage engine
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by list (a)
subpartition by hash (a+b)
( partition x1 values in (1,2,3)
( subpartition x11 nodegroup 0,
subpartition x12 nodegroup 1),
partition x2 values in (4,5,6)
( subpartition x21 nodegroup 0,
subpartition x22 nodegroup 1)
);
INSERT into t1 VALUES (1,1,1);
INSERT into t1 VALUES (4,1,1);
INSERT into t1 VALUES (7,1,1);
ERROR HY000: Got error 1 from storage engine
UPDATE t1 SET a=5 WHERE a=1;
SELECT * from t1;
a b c
5 1 1
4 1 1
UPDATE t1 SET a=6 WHERE a=4;
SELECT * from t1;
a b c
5 1 1
6 1 1
DELETE from t1 WHERE a=6;
SELECT * from t1;
a b c
5 1 1
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by list (a)
subpartition by hash (a+b)
subpartitions 3
( partition x1 values in (1,2,4)
( subpartition x11 nodegroup 0,
subpartition x12 nodegroup 1),
partition x2 values in (3,5,6)
( subpartition x21 nodegroup 0,
subpartition x22 nodegroup 1)
);
ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near '),
partition x2 values in (3,5,6)
( subpartition x21 nodegroup 0,
subpartition x' at line 11
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by list (a)
subpartition by hash (a+b)
( partition x1 values in (1)
( subpartition x11 nodegroup 0,
subpartition xextra,
subpartition x12 nodegroup 1),
partition x2 values in (2)
( subpartition x21 nodegroup 0,
subpartition x22 nodegroup 1)
);
ERROR 42000: Wrong number of subpartitions defined, mismatch with previous setting near ')
)' at line 14
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by list (a+b)
( partition x1
( subpartition x11 engine myisam,
subpartition x12 engine myisam),
partition x2
( subpartition x21 engine myisam,
subpartition x22 engine myisam)
);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'list (a+b)
( partition x1
( subpartition x11 engine myisam,
subpartition x12 eng' at line 7
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by list (a+b)
( partition x1
( subpartition x11 engine myisam values in (0),
subpartition x12 engine myisam values in (1)),
partition x2
( subpartition x21 engine myisam values in (0),
subpartition x22 engine myisam values in (1))
);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'list (a+b)
( partition x1
( subpartition x11 engine myisam values in (0),
subpar' at line 7
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
(partition x1 values in (1,2,9,4) tablespace ts1);
drop table t1;
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a);
ERROR HY000: For LIST partitions each partition must be defined
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (3+4)
partitions 2
(partition x1 values in (4) tablespace ts1,
partition x2 values in (8) tablespace ts2);
ERROR HY000: Constant/Random expression in (sub)partitioning function is not allowed
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a+d)
partitions 2
(partition x1 values in (4) tablespace ts1,
partition x2 values in (8) tablespace ts2);
ERROR 42S22: Unknown column 'd' in 'partition function'
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4),
partition x2);
ERROR HY000: LIST PARTITIONING requires definition of VALUES IN for each partition
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4),
partition x2 values less than (5));
ERROR HY000: Only RANGE PARTITIONING can use VALUES LESS THAN in partition definition
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4,6),
partition x2);
ERROR HY000: LIST PARTITIONING requires definition of VALUES IN for each partition
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4, 12+9),
partition x2 values in (3, 21));
ERROR HY000: Multiple definition of same constant in list partitioning
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4.0, 12+8),
partition x2 values in (3, 21));
ERROR HY000: VALUES IN value must be of same type as partition function
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in 4,
partition x2 values in (5));
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '4,
partition x2 values in (5))' at line 8
This diff is collapsed.
This diff is collapsed.
-- source include/have_ndb.inc
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
#
# Basic syntax test
#
# Support for partition key verified
CREATE TABLE t1 (a int, b int, c int, d int, PRIMARY KEY(a,b,c))
ENGINE = NDB
PARTITION BY KEY (a,b);
insert into t1 values (1,1,1,1);
select * from t1;
update t1 set d = 2 where a = 1 and b = 1 and c = 1;
select * from t1;
delete from t1;
select * from t1;
drop table t1;
# only support for partition key on primary key
--error 1453
CREATE TABLE t1 (a int, b int, c int, d int, PRIMARY KEY(a,b))
ENGINE = NDB
PARTITION BY KEY (c);
CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY(a,b))
ENGINE = NDB
PARTITION BY KEY (a);
insert into t1 values
(1,1,3),(1,2,3),(1,3,3),(1,4,3),(1,5,3),(1,6,3),
(1,7,3),(1,8,3),(1,9,3),(1,10,3),(1,11,3),(1,12,3);
select * from t1 order by b;
DROP TABLE t1;
#
# Test partition and char support
#
CREATE TABLE t1 (a INT, b CHAR(10) COLLATE latin1_bin, c INT, d INT,
PRIMARY KEY USING HASH (a,b,c))
ENGINE=NDB
DEFAULT CHARSET=latin1
PARTITION BY KEY (b);
insert into t1 values (1,"a",1,1),(2,"a",1,1),(3,"a",1,1);
# should show only one attribute with DISTRIBUTION KEY
--exec $NDB_TOOLS_DIR/ndb_desc --no-defaults -d test t1 | sed 's/Version: [0-9]*//'
DROP TABLE t1;
-- source include/have_ndb.inc
#--disable_abort_on_error
#
# Simple test for the partition storage engine
# Focuses on range partitioning tests
#
#-- source include/have_partition.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
#
# Partition by range, basic
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b),
index (a))
engine = ndb
partition by range (a)
partitions 3
(partition x1 values less than (5),
partition x2 values less than (10),
partition x3 values less than (20));
# Simple insert and verify test
INSERT into t1 values (1, 1, 1);
INSERT into t1 values (6, 1, 1);
INSERT into t1 values (10, 1, 1);
INSERT into t1 values (15, 1, 1);
select * from t1 order by a;
select * from t1 where a=1 order by a;
select * from t1 where a=15 and b=1 order by a;
select * from t1 where a=21 and b=1 order by a;
select * from t1 where a=21 order by a;
select * from t1 where a in (1,6,10,21) order by a;
select * from t1 where b=1 and a in (1,6,10,21) order by a;
drop table t1;
#
# Partition by range, basic
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(b),
unique (a))
engine = ndb
partition by range (b)
partitions 3
(partition x1 values less than (5),
partition x2 values less than (10),
partition x3 values less than (20));
# Simple insert and verify test
INSERT into t1 values (1, 1, 1);
INSERT into t1 values (2, 6, 1);
INSERT into t1 values (3, 10, 1);
INSERT into t1 values (4, 15, 1);
select * from t1 order by a;
UPDATE t1 set a = 5 WHERE b = 15;
select * from t1 order by a;
UPDATE t1 set a = 6 WHERE a = 5;
select * from t1 order by a;
select * from t1 where b=1 order by b;
select * from t1 where b=15 and a=1 order by b;
select * from t1 where b=21 and a=1 order by b;
select * from t1 where b=21 order by b;
select * from t1 where b in (1,6,10,21) order by b;
select * from t1 where a in (1,2,5,6) order by b;
select * from t1 where a=1 and b in (1,6,10,21) order by b;
DELETE from t1 WHERE b = 6;
DELETE from t1 WHERE a = 6;
drop table t1;
#--disable_abort_on_error
#
# Simple test for the partition storage engine
# Taken fromm the select test
#
-- source include/have_partition.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
#
# Partition by key no partition defined => OK
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a);
drop table t1;
#
# Partition by key no partition, list of fields
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a, b);
drop table t1;
#
# Partition by key specified 3 partitions and defined 3 => ok
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a)
partitions 3
(partition x1, partition x2, partition x3);
drop table t1;
#
# Partition by key specifying nodegroup
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a)
partitions 3
(partition x1 nodegroup 0,
partition x2 nodegroup 1,
partition x3 nodegroup 2);
drop table t1;
#
# Partition by key specifying engine
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a)
partitions 3
(partition x1 engine myisam,
partition x2 engine myisam,
partition x3 engine myisam);
drop table t1;
#
# Partition by key specifying tablespace
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a)
partitions 3
(partition x1 tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
drop table t1;
#
# Partition by key list, basic
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 3
(partition x1 values in (1,2,9,4) tablespace ts1,
partition x2 values in (3, 11, 5, 7) tablespace ts2,
partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3);
drop table t1;
#
# Partition by key list, list function
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (b*a)
partitions 3
(partition x1 values in (1,2,9,4) tablespace ts1,
partition x2 values in (3, 11, 5, 7) tablespace ts2,
partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3);
drop table t1;
#
# Partition by key list, list function, no spec of #partitions
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (b*a)
(partition x1 values in (1) tablespace ts1,
partition x2 values in (3, 11, 5, 7) tablespace ts2,
partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3);
drop table t1;
#
# Partition by key stand-alone error
#
--error 1064
partition by list (a)
partitions 3
(partition x1 values in (1,2,9,4) tablespace ts1,
partition x2 values in (3, 11, 5, 7) tablespace ts2,
partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3);
#
# Partition by key list, number of partitions defined, no partition defined
#
--error 1441
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2;
#
# Partition by key list, wrong result type
#
--error 1440
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (sin(a))
partitions 3
(partition x1 values in (1,2,9,4) tablespace ts1,
partition x2 values in (3, 11, 5, 7) tablespace ts2,
partition x3 values in (16, 8, 5+19, 70-43) tablespace ts3);
#
# Partition by key, partition function not allowed
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a+2)
partitions 3
(partition x1 tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
#
# Partition by key, no partition name
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a)
partitions 3
(partition tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
#
# Partition by key, invalid field in field list
#
--error 1437
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a,d)
partitions 3
(partition x1 tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
#
# Partition by hash, invalid field in function
#
--error 1054
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (a + d)
partitions 3
(partition x1 tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
#
# Partition by hash, invalid result type
#
--error 1440
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (sin(a))
partitions 3
(partition x1 tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
#
# Partition by key specified 3 partitions but only defined 2 => error
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a)
partitions 3
(partition x1, partition x2);
#
# Partition by key specified 3 partitions but only defined 2 => error
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (rand(a))
partitions 2
(partition x1, partition x2);
#
# Partition by key specified 3 partitions but only defined 2 => error
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by range (rand(a))
partitions 2
(partition x1 values less than (0), partition x2 values less than (2));
#
# Partition by key specified 3 partitions but only defined 2 => error
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (rand(a))
partitions 2
(partition x1 values in (1), partition x2 values in (2));
#
# Partition by hash, values less than error
#
--error 1430
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (a)
partitions 2
(partition x1 values less than (4),
partition x2 values less than (5));
#
# Partition by hash, values in error
#
--error 1430
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (a)
partitions 2
(partition x1 values in (4),
partition x2 values in (5));
#
# Partition by hash, values in error
#
--error 1430
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (a)
partitions 2
(partition x1 values in (4,6),
partition x2 values in (5,7));
#
# Subpartition by key, no partitions defined, single field
#
--error 1449
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by key (b);
#
# Subpartition by key, no partitions defined, list of fields
#
--error 1449
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by key (a, b);
#
# Subpartition by hash, no partitions defined
#
--error 1449
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by hash (a+b);
#
# Subpartition by key, no partitions defined, single field
#
--error 1449
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by key (b);
#
# Subpartition by key, no partitions defined, list of fields
#
--error 1449
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by key (a, b);
#
# Subpartition by hash, no partitions defined
#
--error 1449
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by hash (a+b);
#
# Subpartition by hash, no partitions defined, wrong subpartition function
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by hash (rand(a+b));
#
# Subpartition by hash, wrong subpartition function
#
--error 1449
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by hash (sin(a+b))
(partition x1 (subpartition x11, subpartition x12),
partition x2 (subpartition x21, subpartition x22));
#
# Subpartition by hash, no partitions defined, wrong subpartition function
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by key (a+b)
(partition x1 values less than (1) (subpartition x11, subpartition x12),
partition x2 values less than (2) (subpartition x21, subpartition x22));
#
# Subpartition by hash, no partitions defined, wrong subpartition function
#
--error 1437
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by key (a,d)
(partition x1 values less than (1) (subpartition x11, subpartition x12),
partition x2 values less than (2) (subpartition x21, subpartition x22));
#
# Subpartition by hash, no partitions defined, wrong subpartition function
#
--error 1449
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by hash (3+4);
#
# Subpartition by hash, no partitions defined, wrong subpartition function
#
--error 1054
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by range (a)
subpartition by hash (a+d)
(partition x1 values less than (1) (subpartition x11, subpartition x12),
partition x2 values less than (2) (subpartition x21, subpartition x22));
#--disable_abort_on_error
#
# Simple test for the partition storage engine
# Taken fromm the select test
#
-- source include/have_partition.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
#
# Partition by hash, basic
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (a + 2)
partitions 3
(partition x1 tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
insert into t1 values (1,1,1);
insert into t1 values (2,1,1);
insert into t1 values (3,1,1);
insert into t1 values (4,1,1);
insert into t1 values (5,1,1);
select * from t1;
update t1 set c=3 where b=1;
select * from t1;
select b from t1 where a=3;
select b,c from t1 where a=1 AND b=1;
delete from t1 where a=1;
delete from t1 where c=3;
select * from t1;
ALTER TABLE t1
partition by hash (a + 3)
partitions 3
(partition x1 tablespace ts1,
partition x2 tablespace ts2,
partition x3 tablespace ts3);
select * from t1;
drop table t1;
#
# Partition by hash, only one partition
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by hash (a)
(partition x1);
drop table t1;
#
# Partition by key, only one partition
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by key (a)
(partition x1);
drop table t1;
#--disable_abort_on_error
#
# Simple test for the partition storage engine
# testing list partitioning
#
-- source include/have_partition.inc
--disable_warnings
drop table if exists t1;
--enable_warnings
#
# Test ordinary list partitioning that it works ok
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null)
partition by list(a)
partitions 2
(partition x123 values in (1,5,6),
partition x234 values in (4,7,8));
INSERT into t1 VALUES (1,1,1);
--error 1030
INSERT into t1 VALUES (2,1,1);
--error 1030
INSERT into t1 VALUES (3,1,1);
INSERT into t1 VALUES (4,1,1);
INSERT into t1 VALUES (5,1,1);
INSERT into t1 VALUES (6,1,1);
INSERT into t1 VALUES (7,1,1);
INSERT into t1 VALUES (8,1,1);
--error 1030
INSERT into t1 VALUES (9,1,1);
INSERT into t1 VALUES (1,2,1);
INSERT into t1 VALUES (1,3,1);
INSERT into t1 VALUES (1,4,1);
INSERT into t1 VALUES (7,2,1);
INSERT into t1 VALUES (7,3,1);
INSERT into t1 VALUES (7,4,1);
SELECT * from t1;
SELECT * from t1 WHERE a=1;
SELECT * from t1 WHERE a=7;
SELECT * from t1 WHERE b=2;
UPDATE t1 SET a=8 WHERE a=7 AND b=3;
SELECT * from t1;
UPDATE t1 SET a=8 WHERE a=5 AND b=1;
SELECT * from t1;
DELETE from t1 WHERE a=8;
SELECT * from t1;
DELETE from t1 WHERE a=2;
SELECT * from t1;
DELETE from t1 WHERE a=5 OR a=6;
SELECT * from t1;
ALTER TABLE t1
partition by list(a)
partitions 2
(partition x123 values in (1,5,6),
partition x234 values in (4,7,8));
SELECT * from t1;
INSERT into t1 VALUES (6,2,1);
--error 1030
INSERT into t1 VALUES (2,2,1);
drop table t1;
#
# Subpartition by hash, two partitions and two subpartitions
# Defined node group
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by list (a)
subpartition by hash (a+b)
( partition x1 values in (1,2,3)
( subpartition x11 nodegroup 0,
subpartition x12 nodegroup 1),
partition x2 values in (4,5,6)
( subpartition x21 nodegroup 0,
subpartition x22 nodegroup 1)
);
INSERT into t1 VALUES (1,1,1);
INSERT into t1 VALUES (4,1,1);
--error 1030
INSERT into t1 VALUES (7,1,1);
UPDATE t1 SET a=5 WHERE a=1;
SELECT * from t1;
UPDATE t1 SET a=6 WHERE a=4;
SELECT * from t1;
DELETE from t1 WHERE a=6;
SELECT * from t1;
drop table t1;
#
# Subpartition by hash, wrong number of subpartitions
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by list (a)
subpartition by hash (a+b)
subpartitions 3
( partition x1 values in (1,2,4)
( subpartition x11 nodegroup 0,
subpartition x12 nodegroup 1),
partition x2 values in (3,5,6)
( subpartition x21 nodegroup 0,
subpartition x22 nodegroup 1)
);
#
# Subpartition by hash, wrong number of subpartitions
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by list (a)
subpartition by hash (a+b)
( partition x1 values in (1)
( subpartition x11 nodegroup 0,
subpartition xextra,
subpartition x12 nodegroup 1),
partition x2 values in (2)
( subpartition x21 nodegroup 0,
subpartition x22 nodegroup 1)
);
#
# Subpartition by list => error
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by list (a+b)
( partition x1
( subpartition x11 engine myisam,
subpartition x12 engine myisam),
partition x2
( subpartition x21 engine myisam,
subpartition x22 engine myisam)
);
#
# Subpartition by list => error
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key (a,b))
partition by key (a)
subpartition by list (a+b)
( partition x1
( subpartition x11 engine myisam values in (0),
subpartition x12 engine myisam values in (1)),
partition x2
( subpartition x21 engine myisam values in (0),
subpartition x22 engine myisam values in (1))
);
#
# Partition by list, only one partition => ok
#
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
(partition x1 values in (1,2,9,4) tablespace ts1);
drop table t1;
#
# Partition by list, no partition => error
#
--error 1441
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a);
#
# Partition by list, constant partition function not allowed
#
--error 1435
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (3+4)
partitions 2
(partition x1 values in (4) tablespace ts1,
partition x2 values in (8) tablespace ts2);
#
# Partition by list, invalid field in function
#
--error 1054
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a+d)
partitions 2
(partition x1 values in (4) tablespace ts1,
partition x2 values in (8) tablespace ts2);
#
# Partition by list, no values in definition
#
--error 1429
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4),
partition x2);
#
# Partition by list, values less than error
#
--error 1430
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4),
partition x2 values less than (5));
#
# Partition by list, no values in definition
#
--error 1429
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4,6),
partition x2);
#
# Partition by list, duplicate values
#
--error 1444
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4, 12+9),
partition x2 values in (3, 21));
#
# Partition by list, wrong constant result type (not INT)
#
--error 1443
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in (4.0, 12+8),
partition x2 values in (3, 21));
#
# Partition by list, missing parenthesis
#
--error 1064
CREATE TABLE t1 (
a int not null,
b int not null,
c int not null,
primary key(a,b))
partition by list (a)
partitions 2
(partition x1 values in 4,
partition x2 values in (5));
This diff is collapsed.
This diff is collapsed.
......@@ -84,6 +84,9 @@ FLAGS=$(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) @NOINST_LDFLAGS@
test_bitmap$(EXEEXT): my_bitmap.c $(LIBRARIES)
$(LINK) $(FLAGS) -DMAIN ./my_bitmap.c $(LDADD) $(LIBS)
test_priority_queue$(EXEEXT): queues.c $(LIBRARIES)
$(LINK) $(FLAGS) -DMAIN ./queues.c $(LDADD) $(LIBS)
test_thr_alarm$(EXEEXT): thr_alarm.c $(LIBRARIES)
$(CP) $(srcdir)/thr_alarm.c ./test_thr_alarm.c
$(LINK) $(FLAGS) -DMAIN ./test_thr_alarm.c $(LDADD) $(LIBS)
......
......@@ -20,20 +20,20 @@
API limitations (or, rather asserted safety assumptions,
to encourage correct programming)
* the size of the used bitmap is less than ~(uint) 0
* it's a multiple of 8 (for efficiency reasons)
* when arguments are a bitmap and a bit number, the number
must be within bitmap size
* bitmap_set_prefix() is an exception - one can use ~0 to set all bits
* when both arguments are bitmaps, they must be of the same size
* bitmap_intersect() is an exception :)
(for for Bitmap::intersect(ulonglong map2buff))
If THREAD is defined all bitmap operations except bitmap_init/bitmap_free
are thread-safe.
* the internal size is a set of 32 bit words
* the number of bits specified in creation can be any number > 0
* there are THREAD safe versions of most calls called bitmap_lock_*
many of those are not used and not compiled normally but the code
already exist for them in an #ifdef:ed part. These can only be used
if THREAD was specified in bitmap_init
TODO:
Make assembler THREAD safe versions of these using test-and-set instructions
Original version created by Sergei Golubchik 2001 - 2004.
New version written and test program added and some changes to the interface
was made by Mikael Ronström 2005, with assistance of Tomas Ulin and Mats
Kindahl.
*/
#include "mysys_priv.h"
......@@ -1046,17 +1046,9 @@ int main()
}
/*
This is the way the test part was compiled after a complete tree build with
debug.
gcc -DHAVE_CONFIG_H -I. -I. -I.. -I../include -I. -g -O -DDBUG_ON
-DSAFE_MUTEX -fno-omit-frame-pointer -DHAVE_DARWIN_THREADS
-D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DTEST_BITMAP
-DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -MT
my_bitmap.o -MD -MP -MF ".deps/my_bitmap.Tpo" -c -o my_bitmap.o my_bitmap.c
gcc -o my_bitmap my_bitmap.o -L../mysys -lmysys -L../strings -lmystrings
-L../dbug -ldbug
In directory mysys:
make test_bitmap
will build the bitmap tests and ./test_bitmap will execute it
*/
#endif
This diff is collapsed.
......@@ -63,7 +63,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
parse_file.h sql_view.h sql_trigger.h \
examples/ha_example.h examples/ha_archive.h \
examples/ha_tina.h ha_blackhole.h \
ha_federated.h
ha_federated.h ha_partition.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
item_cmpfunc.cc item_strfunc.cc item_timefunc.cc \
......@@ -100,6 +100,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc \
sp_cache.cc parse_file.cc sql_trigger.cc \
examples/ha_example.cc examples/ha_archive.cc \
examples/ha_tina.cc ha_blackhole.cc \
ha_partition.cc sql_partition.cc \
ha_federated.cc
gen_lex_hash_SOURCES = gen_lex_hash.cc
......
......@@ -6311,7 +6311,8 @@ my_decimal *Field_varstring::val_decimal(my_decimal *decimal_value)
}
int Field_varstring::cmp(const char *a_ptr, const char *b_ptr)
int Field_varstring::cmp_max(const char *a_ptr, const char *b_ptr,
uint max_len)
{
uint a_length, b_length;
int diff;
......@@ -6326,6 +6327,8 @@ int Field_varstring::cmp(const char *a_ptr, const char *b_ptr)
a_length= uint2korr(a_ptr);
b_length= uint2korr(b_ptr);
}
set_if_smaller(a_length, max_len);
set_if_smaller(b_length, max_len);
diff= field_charset->coll->strnncollsp(field_charset,
(const uchar*) a_ptr+
length_bytes,
......@@ -6956,13 +6959,16 @@ int Field_blob::cmp(const char *a,uint32 a_length, const char *b,
}
int Field_blob::cmp(const char *a_ptr, const char *b_ptr)
int Field_blob::cmp_max(const char *a_ptr, const char *b_ptr,
uint max_length)
{
char *blob1,*blob2;
memcpy_fixed(&blob1,a_ptr+packlength,sizeof(char*));
memcpy_fixed(&blob2,b_ptr+packlength,sizeof(char*));
return Field_blob::cmp(blob1,get_length(a_ptr),
blob2,get_length(b_ptr));
uint a_len= get_length(a_ptr), b_len= get_length(b_ptr);
set_if_smaller(a_len, max_length);
set_if_smaller(b_len, max_length);
return Field_blob::cmp(blob1,a_len,blob2,b_len);
}
......@@ -7979,6 +7985,35 @@ my_decimal *Field_bit::val_decimal(my_decimal *deciaml_value)
}
/*
Compare two bit fields using pointers within the record.
SYNOPSIS
cmp_max()
a Pointer to field->ptr in first record
b Pointer to field->ptr in second record
max_len Maximum length used in index
DESCRIPTION
This method is used from key_rec_cmp used by merge sorts used
by partitioned index read and later other similar places.
The a and b pointer must be pointers to the field in a record
(not the table->record[0] necessarily)
*/
int Field_bit::cmp_max(const char *a, const char *b, uint max_len)
{
my_ptrdiff_t a_diff= a - ptr;
my_ptrdiff_t b_diff= b - ptr;
if (bit_len)
{
int flag;
uchar bits_a= get_rec_bits(bit_ptr+a_diff, bit_ofs, bit_len);
uchar bits_b= get_rec_bits(bit_ptr+b_diff, bit_ofs, bit_len);
if ((flag= (int) (bits_a - bits_b)))
return flag;
}
return memcmp(a, b, field_length);
}
int Field_bit::key_cmp(const byte *str, uint length)
{
if (bit_len)
......
......@@ -87,7 +87,7 @@ class Field
utype unireg_check;
uint32 field_length; // Length of field
uint field_index; // field number in fields array
uint16 flags;
uint32 flags;
/* fieldnr is the id of the field (first field = 1) as is also
used in key_part.
*/
......@@ -154,6 +154,8 @@ class Field
virtual enum_field_types type() const =0;
virtual enum_field_types real_type() const { return type(); }
inline int cmp(const char *str) { return cmp(ptr,str); }
virtual int cmp_max(const char *a, const char *b, uint max_len)
{ return cmp(a, b); }
virtual int cmp(const char *,const char *)=0;
virtual int cmp_binary(const char *a,const char *b, uint32 max_length=~0L)
{ return memcmp(a,b,pack_length()); }
......@@ -1059,7 +1061,11 @@ class Field_varstring :public Field_longstr {
longlong val_int(void);
String *val_str(String*,String *);
my_decimal *val_decimal(my_decimal *);
int cmp(const char *,const char*);
int cmp_max(const char *, const char *, uint max_length);
int cmp(const char *a,const char*b)
{
return cmp_max(a, b, ~0);
}
void sort_string(char *buff,uint length);
void get_key_image(char *buff,uint length, imagetype type);
void set_key_image(char *buff,uint length);
......@@ -1115,7 +1121,9 @@ class Field_blob :public Field_longstr {
longlong val_int(void);
String *val_str(String*,String *);
my_decimal *val_decimal(my_decimal *);
int cmp(const char *,const char*);
int cmp_max(const char *, const char *, uint max_length);
int cmp(const char *a,const char*b)
{ return cmp_max(a, b, ~0); }
int cmp(const char *a, uint32 a_length, const char *b, uint32 b_length);
int cmp_binary(const char *a,const char *b, uint32 max_length=~0L);
int key_cmp(const byte *,const byte*);
......@@ -1139,6 +1147,10 @@ class Field_blob :public Field_longstr {
{
memcpy_fixed(str,ptr+packlength,sizeof(char*));
}
inline void get_ptr(char **str, uint row_offset)
{
memcpy_fixed(str,ptr+packlength+row_offset,sizeof(char*));
}
inline void set_ptr(char *length,char *data)
{
memcpy(ptr,length,packlength);
......@@ -1307,6 +1319,7 @@ class Field_bit :public Field {
my_decimal *val_decimal(my_decimal *);
int cmp(const char *a, const char *b)
{ return cmp_binary(a, b); }
int cmp_max(const char *a, const char *b, uint max_length);
int key_cmp(const byte *a, const byte *b)
{ return cmp_binary((char *) a, (char *) b); }
int key_cmp(const byte *str, uint length);
......
......@@ -1360,7 +1360,7 @@ int ha_berkeley::delete_row(const byte * record)
}
int ha_berkeley::index_init(uint keynr)
int ha_berkeley::index_init(uint keynr, bool sorted)
{
int error;
DBUG_ENTER("ha_berkeley::index_init");
......@@ -1638,7 +1638,7 @@ int ha_berkeley::rnd_init(bool scan)
{
DBUG_ENTER("rnd_init");
current_row.flags=DB_DBT_REALLOC;
DBUG_RETURN(index_init(primary_key));
DBUG_RETURN(index_init(primary_key, 0));
}
int ha_berkeley::rnd_end()
......@@ -2146,7 +2146,7 @@ ulonglong ha_berkeley::get_auto_increment()
(void) ha_berkeley::extra(HA_EXTRA_KEYREAD);
/* Set 'active_index' */
ha_berkeley::index_init(table->s->next_number_index);
ha_berkeley::index_init(table->s->next_number_index, 0);
if (!table->s->next_number_key_offset)
{ // Autoincrement at key-start
......@@ -2485,7 +2485,7 @@ void ha_berkeley::get_status()
if (!(share->status & STATUS_PRIMARY_KEY_INIT))
{
(void) extra(HA_EXTRA_KEYREAD);
index_init(primary_key);
index_init(primary_key, 0);
if (!index_last(table->record[1]))
share->auto_ident=uint5korr(current_ident);
index_end();
......
......@@ -98,7 +98,7 @@ class ha_berkeley: public handler
const char **bas_ext() const;
ulong table_flags(void) const { return int_table_flags; }
uint max_supported_keys() const { return MAX_KEY-1; }
uint extra_rec_buf_length() { return BDB_HIDDEN_PRIMARY_KEY_LENGTH; }
uint extra_rec_buf_length() const { return BDB_HIDDEN_PRIMARY_KEY_LENGTH; }
ha_rows estimate_rows_upper_bound();
const key_map *keys_to_use_for_scanning() { return &key_map_full; }
bool has_transactions() { return 1;}
......@@ -109,7 +109,7 @@ class ha_berkeley: public handler
int write_row(byte * buf);
int update_row(const byte * old_data, byte * new_data);
int delete_row(const byte * buf);
int index_init(uint index);
int index_init(uint index, bool sorted);
int index_end();
int index_read(byte * buf, const byte * key,
uint key_len, enum ha_rkey_function find_flag);
......
......@@ -1512,7 +1512,7 @@ int ha_federated::index_read_idx(byte *buf, uint index, const byte *key,
}
/* Initialized at each key walk (called multiple times unlike rnd_init()) */
int ha_federated::index_init(uint keynr)
int ha_federated::index_init(uint keynr, bool sorted)
{
DBUG_ENTER("ha_federated::index_init");
DBUG_PRINT("info",
......
......@@ -154,7 +154,7 @@ class ha_federated: public handler
int write_row(byte * buf);
int update_row(const byte * old_data, byte * new_data);
int delete_row(const byte * buf);
int index_init(uint keynr);
int index_init(uint keynr, bool sorted);
int index_read(byte * buf, const byte * key,
uint key_len, enum ha_rkey_function find_flag);
int index_read_idx(byte * buf, uint idx, const byte * key,
......
......@@ -3595,7 +3595,8 @@ int
ha_innobase::index_init(
/*====================*/
/* out: 0 or error number */
uint keynr) /* in: key (index) number */
uint keynr, /* in: key (index) number */
bool sorted) /* in: 1 if result MUST be sorted according to index */
{
int error = 0;
DBUG_ENTER("index_init");
......@@ -6646,7 +6647,7 @@ ha_innobase::innobase_read_and_init_auto_inc(
}
(void) extra(HA_EXTRA_KEYREAD);
index_init(table->s->next_number_index);
index_init(table->s->next_number_index, 1);
/* Starting from 5.0.9, we use a consistent read to read the auto-inc
column maximum value. This eliminates the spurious deadlocks caused
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment