Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
634a1362
Commit
634a1362
authored
Nov 30, 2004
by
joreland@mysql.com
Browse files
Options
Browse Files
Download
Plain Diff
Merge joreland@bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/home/jonas/src/mysql-5.0
parents
86c57bd8
85f8ad7b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
94 additions
and
6 deletions
+94
-6
mysql-test/r/ndb_index_unique.result
mysql-test/r/ndb_index_unique.result
+36
-0
mysql-test/t/ndb_index_unique.test
mysql-test/t/ndb_index_unique.test
+20
-0
sql/ha_ndbcluster.cc
sql/ha_ndbcluster.cc
+38
-6
No files found.
mysql-test/r/ndb_index_unique.result
View file @
634a1362
...
@@ -574,3 +574,39 @@ uid gid rid cid
...
@@ -574,3 +574,39 @@ uid gid rid cid
1 1 2 3
1 1 2 3
1 1 2 4
1 1 2 4
drop table t1,t2,t3,t4,t5,t6,t7;
drop table t1,t2,t3,t4,t5,t6,t7;
CREATE TABLE t1 (
a int unsigned NOT NULL PRIMARY KEY,
b int unsigned,
c int unsigned,
UNIQUE bc(b,c) ) engine = ndb;
insert into t1 values(1,1,1),(2,NULL,2),(3,NULL,NULL),(4,4,NULL);
select * from t1 where b=1 and c=1;
a b c
1 1 1
select * from t1 where b is null and c is null;
a b c
3 NULL NULL
select * from t1 where b is null and c = 2;
a b c
2 NULL 2
select * from t1 where b = 4 and c is null;
a b c
4 4 NULL
create table t8 as
select * from t1 where (b = 1 and c = 1)
or (b is null and c is null)
or (b is null and c = 2)
or (b = 4 and c is null);
select * from t8 order by a;
a b c
1 1 1
2 NULL 2
3 NULL NULL
4 4 NULL
select * from t1 order by a;
a b c
1 1 1
2 NULL 2
3 NULL NULL
4 4 NULL
drop table t1, t8;
mysql-test/t/ndb_index_unique.test
View file @
634a1362
...
@@ -265,4 +265,24 @@ select * from t4 where rid = 2 order by cid;
...
@@ -265,4 +265,24 @@ select * from t4 where rid = 2 order by cid;
drop
table
t1
,
t2
,
t3
,
t4
,
t5
,
t6
,
t7
;
drop
table
t1
,
t2
,
t3
,
t4
,
t5
,
t6
,
t7
;
# test null in indexes
CREATE
TABLE
t1
(
a
int
unsigned
NOT
NULL
PRIMARY
KEY
,
b
int
unsigned
,
c
int
unsigned
,
UNIQUE
bc
(
b
,
c
)
)
engine
=
ndb
;
insert
into
t1
values
(
1
,
1
,
1
),(
2
,
NULL
,
2
),(
3
,
NULL
,
NULL
),(
4
,
4
,
NULL
);
select
*
from
t1
where
b
=
1
and
c
=
1
;
select
*
from
t1
where
b
is
null
and
c
is
null
;
select
*
from
t1
where
b
is
null
and
c
=
2
;
select
*
from
t1
where
b
=
4
and
c
is
null
;
create
table
t8
as
select
*
from
t1
where
(
b
=
1
and
c
=
1
)
or
(
b
is
null
and
c
is
null
)
or
(
b
is
null
and
c
=
2
)
or
(
b
=
4
and
c
is
null
);
select
*
from
t8
order
by
a
;
select
*
from
t1
order
by
a
;
drop
table
t1
,
t8
;
sql/ha_ndbcluster.cc
View file @
634a1362
...
@@ -1197,9 +1197,10 @@ int ha_ndbcluster::unique_index_read(const byte *key,
...
@@ -1197,9 +1197,10 @@ int ha_ndbcluster::unique_index_read(const byte *key,
for
(
i
=
0
;
key_part
!=
end
;
key_part
++
,
i
++
)
for
(
i
=
0
;
key_part
!=
end
;
key_part
++
,
i
++
)
{
{
if
(
set_ndb_key
(
op
,
key_part
->
field
,
i
,
key_ptr
))
if
(
set_ndb_key
(
op
,
key_part
->
field
,
i
,
key_part
->
null_bit
?
key_ptr
+
1
:
key_ptr
))
ERR_RETURN
(
trans
->
getNdbError
());
ERR_RETURN
(
trans
->
getNdbError
());
key_ptr
+=
key_part
->
length
;
key_ptr
+=
key_part
->
store_
length
;
}
}
// Get non-index attribute(s)
// Get non-index attribute(s)
...
@@ -2290,6 +2291,28 @@ int ha_ndbcluster::index_end()
...
@@ -2290,6 +2291,28 @@ int ha_ndbcluster::index_end()
DBUG_RETURN
(
close_scan
());
DBUG_RETURN
(
close_scan
());
}
}
/**
* Check if key contains null
*/
static
int
check_null_in_key
(
const
KEY
*
key_info
,
const
byte
*
key
,
uint
key_len
)
{
KEY_PART_INFO
*
curr_part
,
*
end_part
;
const
byte
*
end_ptr
=
key
+
key_len
;
curr_part
=
key_info
->
key_part
;
end_part
=
curr_part
+
key_info
->
key_parts
;
for
(;
curr_part
!=
end_part
&&
key
<
end_ptr
;
curr_part
++
)
{
if
(
curr_part
->
null_bit
&&
*
key
)
return
1
;
key
+=
curr_part
->
store_length
;
}
return
0
;
}
int
ha_ndbcluster
::
index_read
(
byte
*
buf
,
int
ha_ndbcluster
::
index_read
(
byte
*
buf
,
const
byte
*
key
,
uint
key_len
,
const
byte
*
key
,
uint
key_len
,
...
@@ -2307,6 +2330,8 @@ int ha_ndbcluster::index_read(byte *buf,
...
@@ -2307,6 +2330,8 @@ int ha_ndbcluster::index_read(byte *buf,
case
PRIMARY_KEY_INDEX
:
case
PRIMARY_KEY_INDEX
:
if
(
find_flag
==
HA_READ_KEY_EXACT
&&
key_info
->
key_length
==
key_len
)
if
(
find_flag
==
HA_READ_KEY_EXACT
&&
key_info
->
key_length
==
key_len
)
{
{
if
(
m_active_cursor
&&
(
error
=
close_scan
()))
DBUG_RETURN
(
error
);
DBUG_RETURN
(
pk_read
(
key
,
key_len
,
buf
));
DBUG_RETURN
(
pk_read
(
key
,
key_len
,
buf
));
}
}
else
if
(
type
==
PRIMARY_KEY_INDEX
)
else
if
(
type
==
PRIMARY_KEY_INDEX
)
...
@@ -2316,8 +2341,11 @@ int ha_ndbcluster::index_read(byte *buf,
...
@@ -2316,8 +2341,11 @@ int ha_ndbcluster::index_read(byte *buf,
break
;
break
;
case
UNIQUE_ORDERED_INDEX
:
case
UNIQUE_ORDERED_INDEX
:
case
UNIQUE_INDEX
:
case
UNIQUE_INDEX
:
if
(
find_flag
==
HA_READ_KEY_EXACT
&&
key_info
->
key_length
==
key_len
)
if
(
find_flag
==
HA_READ_KEY_EXACT
&&
key_info
->
key_length
==
key_len
&&
!
check_null_in_key
(
key_info
,
key
,
key_len
))
{
{
if
(
m_active_cursor
&&
(
error
=
close_scan
()))
DBUG_RETURN
(
error
);
DBUG_RETURN
(
unique_index_read
(
key
,
key_len
,
buf
));
DBUG_RETURN
(
unique_index_read
(
key
,
key_len
,
buf
));
}
}
else
if
(
type
==
UNIQUE_INDEX
)
else
if
(
type
==
UNIQUE_INDEX
)
...
@@ -2424,6 +2452,8 @@ int ha_ndbcluster::read_range_first_to_buf(const key_range *start_key,
...
@@ -2424,6 +2452,8 @@ int ha_ndbcluster::read_range_first_to_buf(const key_range *start_key,
start_key
->
length
==
key_info
->
key_length
&&
start_key
->
length
==
key_info
->
key_length
&&
start_key
->
flag
==
HA_READ_KEY_EXACT
)
start_key
->
flag
==
HA_READ_KEY_EXACT
)
{
{
if
(
m_active_cursor
&&
(
error
=
close_scan
()))
DBUG_RETURN
(
error
);
error
=
pk_read
(
start_key
->
key
,
start_key
->
length
,
buf
);
error
=
pk_read
(
start_key
->
key
,
start_key
->
length
,
buf
);
DBUG_RETURN
(
error
==
HA_ERR_KEY_NOT_FOUND
?
HA_ERR_END_OF_FILE
:
error
);
DBUG_RETURN
(
error
==
HA_ERR_KEY_NOT_FOUND
?
HA_ERR_END_OF_FILE
:
error
);
}
}
...
@@ -2431,10 +2461,12 @@ int ha_ndbcluster::read_range_first_to_buf(const key_range *start_key,
...
@@ -2431,10 +2461,12 @@ int ha_ndbcluster::read_range_first_to_buf(const key_range *start_key,
case
UNIQUE_ORDERED_INDEX
:
case
UNIQUE_ORDERED_INDEX
:
case
UNIQUE_INDEX
:
case
UNIQUE_INDEX
:
key_info
=
table
->
key_info
+
active_index
;
key_info
=
table
->
key_info
+
active_index
;
if
(
start_key
&&
if
(
start_key
&&
start_key
->
length
==
key_info
->
key_length
&&
start_key
->
length
==
key_info
->
key_length
&&
start_key
->
flag
==
HA_READ_KEY_EXACT
&&
start_key
->
flag
==
HA_READ_KEY_EXACT
)
!
check_null_in_key
(
key_info
,
start_key
->
key
,
start_key
->
length
)
)
{
{
if
(
m_active_cursor
&&
(
error
=
close_scan
()))
DBUG_RETURN
(
error
);
error
=
unique_index_read
(
start_key
->
key
,
start_key
->
length
,
buf
);
error
=
unique_index_read
(
start_key
->
key
,
start_key
->
length
,
buf
);
DBUG_RETURN
(
error
==
HA_ERR_KEY_NOT_FOUND
?
HA_ERR_END_OF_FILE
:
error
);
DBUG_RETURN
(
error
==
HA_ERR_KEY_NOT_FOUND
?
HA_ERR_END_OF_FILE
:
error
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment