Commit c708619d authored by mskold@mysql.com's avatar mskold@mysql.com

Added support for update of pk

parent 5e6a1a89
......@@ -3,25 +3,35 @@ CREATE TABLE t1 (
pk1 INT NOT NULL PRIMARY KEY,
attr1 INT NOT NULL
) ENGINE=ndbcluster;
INSERT INTO t1 VALUES (9410,9412);
INSERT INTO t1 VALUES (9410,9412),(9411,9413);
SELECT pk1 FROM t1;
pk1
9410
9411
SELECT * FROM t1;
pk1 attr1
9410 9412
9411 9413
SELECT t1.* FROM t1;
pk1 attr1
9410 9412
9411 9413
UPDATE t1 SET attr1=1 WHERE pk1=9410;
SELECT * FROM t1;
pk1 attr1
9410 1
9411 9413
UPDATE t1 SET pk1=2 WHERE attr1=1;
ERROR 42000: Table 't1' uses an extension that doesn't exist in this MySQL version
SELECT * FROM t1;
pk1 attr1
9410 1
2 1
9411 9413
UPDATE t1 SET pk1=2 WHERE attr1=9413;
ERROR 23000: Can't write; duplicate key in table 't1'
SELECT * FROM t1;
pk1 attr1
2 1
9411 9413
DELETE FROM t1;
SELECT * FROM t1;
pk1 attr1
......
......@@ -17,7 +17,7 @@ CREATE TABLE t1 (
attr1 INT NOT NULL
) ENGINE=ndbcluster;
INSERT INTO t1 VALUES (9410,9412);
INSERT INTO t1 VALUES (9410,9412),(9411,9413);
SELECT pk1 FROM t1;
SELECT * FROM t1;
......@@ -27,11 +27,16 @@ SELECT t1.* FROM t1;
UPDATE t1 SET attr1=1 WHERE pk1=9410;
SELECT * FROM t1;
# Can't UPDATE PK! Test that correct error is returned
-- error 1112
# Update pk
UPDATE t1 SET pk1=2 WHERE attr1=1;
SELECT * FROM t1;
# Try to set same pk
# 1022: Can't write; duplicate key in table 't1'
-- error 1022
UPDATE t1 SET pk1=2 WHERE attr1=9413;
SELECT * FROM t1;
# Delete the record
DELETE FROM t1;
SELECT * FROM t1;
......
......@@ -866,7 +866,8 @@ int ha_ndbcluster::ordered_index_scan(const key_range *start_key,
index_name= get_index_name(active_index);
if (!(op= trans->getNdbIndexScanOperation(index_name, m_tabname)))
ERR_RETURN(trans->getNdbError());
if (!(cursor= op->readTuples(get_ndb_lock_type(m_lock.type), 0,parallelism)))
if (!(cursor= op->readTuples(get_ndb_lock_type(m_lock.type), 0,
parallelism))) //, sorted))) // Bug
ERR_RETURN(trans->getNdbError());
m_active_cursor= cursor;
......@@ -1173,8 +1174,30 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
/* Check for update of primary key and return error */
if ((table->primary_key != MAX_KEY) &&
(key_cmp(table->primary_key, old_data, new_data)))
DBUG_RETURN(HA_ERR_UNSUPPORTED);
{
DBUG_PRINT("info", ("primary key update, doing insert + delete"));
int insert_res = write_row(new_data);
if (!insert_res)
{
DBUG_PRINT("info", ("delete succeded"));
int delete_res = delete_row(old_data);
if (!delete_res)
{
DBUG_PRINT("info", ("insert + delete succeeded"));
DBUG_RETURN(0);
}
else
{
DBUG_PRINT("info", ("delete failed"));
DBUG_RETURN(delete_row(new_data));
}
}
else
{
DBUG_PRINT("info", ("insert failed"));
DBUG_RETURN(insert_res);
}
}
if (cursor)
{
/*
......@@ -2600,10 +2623,12 @@ int ndbcluster_drop_database(const char *path)
longlong ha_ndbcluster::get_auto_increment()
{
DBUG_ENTER("get_auto_increment");
DBUG_PRINT("enter", ("m_tabname: %s", m_tabname));
int cache_size = rows_to_insert ? rows_to_insert : 32;
Uint64 auto_value=
m_ndb->getAutoIncrementValue(m_tabname, cache_size);
return (longlong)auto_value;
DBUG_RETURN((longlong)auto_value);
}
......
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