Commit 893ed9fc authored by unknown's avatar unknown
Browse files

Merge mysql.com:/home/marty/MySQL/mysql-5.0

into  mysql.com:/home/marty/MySQL/mysql-5.1-ndb


mysql-test/r/ndb_read_multi_range.result:
  Auto merged
mysql-test/t/ndb_lock.test:
  Auto merged
mysql-test/t/ndb_read_multi_range.test:
  Auto merged
storage/ndb/include/ndbapi/NdbTransaction.hpp:
  Auto merged
mysql-test/r/ndb_lock.result:
  Merge (using local)
sql/ha_ndbcluster.cc:
  Merge fix for bug #18184  SELECT ... FOR UPDATE does not work..
sql/ha_ndbcluster.h:
  Merge fix for bug #18184  SELECT ... FOR UPDATE does not work..
parents e7fbb26c d81ace87
Loading
Loading
Loading
Loading
+64 −3
Original line number Diff line number Diff line
@@ -286,10 +286,10 @@ INSERT INTO t1 VALUES
(406990,67,'2006-02-23 18:01:45'),(148815,67,'2005-10-25 15:34:17'),
(148812,67,'2005-10-25 15:30:01'),(245651,67,'2005-12-08 15:58:27'),
(154503,67,'2005-10-28 11:52:38');
create table t11 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 asc;
create table t12 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 desc;
create table t11 engine = ndbcluster select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 asc;
create table t12 engine = ndbcluster select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 desc;
create table t21 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 asc;
create table t22 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 desc;
create table t22 engine = ndbcluster select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 desc;
select * from t11 order by 1,2,3;
a	b	c
254	67	NULL
@@ -366,4 +366,65 @@ a b c
406993	67	2006-02-27 11:20:57
406994	67	2006-02-27 11:26:46
406995	67	2006-02-28 11:55:00
select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null order by t12.a;
a
255
256
update t22 set c = '2005-12-08 15:58:27' where a = 255;
select * from t22 order by 1,2,3;
a	b	c
1	67	2006-02-23 15:01:35
254	67	NULL
255	67	2005-12-08 15:58:27
256	67	NULL
1120	67	NULL
1133	67	NULL
4101	67	NULL
9199	67	NULL
223456	67	NULL
245651	67	2005-12-08 15:58:27
245652	67	2005-12-08 15:58:27
245653	67	2005-12-08 15:59:07
245654	67	2005-12-08 15:59:08
245655	67	2005-12-08 15:59:08
398340	67	2006-02-20 04:38:53
398341	67	2006-02-20 04:48:44
398545	67	2006-02-20 04:53:13
406631	67	2006-02-23 10:49:42
406988	67	2006-02-23 17:07:22
406989	67	2006-02-23 17:08:46
406990	67	2006-02-23 18:01:45
406991	67	2006-02-24 16:42:32
406992	67	2006-02-24 16:47:18
406993	67	2006-02-27 11:20:57
406994	67	2006-02-27 11:26:46
406995	67	2006-02-28 11:55:00
select t21.* from t21,t22 where t21.a = t22.a and 
t22.a in (select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null) and t22.c is null order by t21.a;
a	b	c
256	67	NULL
delete from t22 where a > 245651;
update t22 set b = a + 1;
select * from t22 order by 1,2,3;
a	b	c
1	2	2006-02-23 15:01:35
254	255	NULL
255	256	2005-12-08 15:58:27
256	257	NULL
1120	1121	NULL
1133	1134	NULL
4101	4102	NULL
9199	9200	NULL
223456	223457	NULL
245651	245652	2005-12-08 15:58:27
select c, count(*)
from t21 
inner join t22 using (a)
where t22.b in (2,256,257,1121,1134,4102,9200,223457,245652)
group by c
order by c;
c	count(*)
NULL	7
2005-12-08 15:58:27	1
2006-02-23 15:01:35	1
DROP TABLE t1, t11, t12, t21, t22;
+13 −2
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ drop table t1;

create table t1 (x integer not null primary key, y varchar(32), z integer, key(z)) engine = ndb;

insert into t1 values (1,'one',1), (2,'two',2),(3,"three",3); 
insert into t1 values (1,'one',1);

# PK access
connection con1;
@@ -82,11 +82,22 @@ select * from t1 where x = 1 for update;

connection con2;
begin;
select * from t1 where x = 2 for update;
--error 1205
select * from t1 where x = 1 for update;
rollback;

connection con1;
rollback;
insert into t1 values (2,'two',2),(3,"three",3); 
begin;
select * from t1 where x = 1 for update;

connection con2;
--error 1205
select * from t1 where x = 1 for update;
select * from t1 where x = 2 for update;
rollback;

connection con1;
commit;

+22 −3
Original line number Diff line number Diff line
@@ -228,13 +228,32 @@ INSERT INTO t1 VALUES
(148812,67,'2005-10-25 15:30:01'),(245651,67,'2005-12-08 15:58:27'),
(154503,67,'2005-10-28 11:52:38');

create table t11 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 asc;
create table t12 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 desc;
create table t11 engine = ndbcluster select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 asc;
create table t12 engine = ndbcluster select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 desc;
create table t21 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 asc;
create table t22 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 desc;
create table t22 engine = ndbcluster select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 desc;

select * from t11 order by 1,2,3;
select * from t12 order by 1,2,3;
select * from t21 order by 1,2,3;
select * from t22 order by 1,2,3;

# join tests
select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null order by t12.a;

update t22 set c = '2005-12-08 15:58:27' where a = 255;
select * from t22 order by 1,2,3;
select t21.* from t21,t22 where t21.a = t22.a and 
t22.a in (select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null) and t22.c is null order by t21.a;

delete from t22 where a > 245651;
update t22 set b = a + 1;
select * from t22 order by 1,2,3;
select c, count(*)
from t21 
inner join t22 using (a)
where t22.b in (2,256,257,1121,1134,4102,9200,223457,245652)
group by c
order by c;

DROP TABLE t1, t11, t12, t21, t22;
+64 −17
Original line number Diff line number Diff line
@@ -256,13 +256,15 @@ int execute_no_commit_ignore_no_key(ha_ndbcluster *h, NdbTransaction *trans)
}

inline
int execute_no_commit(ha_ndbcluster *h, NdbTransaction *trans)
int execute_no_commit(ha_ndbcluster *h, NdbTransaction *trans, 
		      bool force_release)
{
#ifdef NOT_USED
  int m_batch_execute= 0;
  if (m_batch_execute)
    return 0;
#endif
  h->release_completed_operations(trans, force_release);
  return h->m_ignore_no_key ?
    execute_no_commit_ignore_no_key(h,trans) :
    trans->execute(NdbTransaction::NoCommit,
@@ -297,13 +299,15 @@ int execute_commit(THD *thd, NdbTransaction *trans)
}

inline
int execute_no_commit_ie(ha_ndbcluster *h, NdbTransaction *trans)
int execute_no_commit_ie(ha_ndbcluster *h, NdbTransaction *trans, 
			 bool force_release)
{
#ifdef NOT_USED
  int m_batch_execute= 0;
  if (m_batch_execute)
    return 0;
#endif
  h->release_completed_operations(trans, force_release);
  return trans->execute(NdbTransaction::NoCommit,
                        NdbTransaction::AO_IgnoreError,
                        h->m_force_send);
@@ -328,6 +332,7 @@ Thd_ndb::Thd_ndb()
  all= NULL;
  stmt= NULL;
  error= 0;
  query_state&= NDB_QUERY_NORMAL;
  options= 0;
  (void) hash_init(&open_tables, &my_charset_bin, 5, 0, 0,
                   (hash_get_key)thd_ndb_share_get_key, 0, 0);
@@ -1696,7 +1701,7 @@ int ha_ndbcluster::pk_read(const byte *key, uint key_len, byte *buf,
      ERR_RETURN(trans->getNdbError());
  }

  if (execute_no_commit_ie(this,trans) != 0) 
  if (execute_no_commit_ie(this,trans,false) != 0) 
  {
    table->status= STATUS_NOT_FOUND;
    DBUG_RETURN(ndb_err(trans));
@@ -1761,7 +1766,7 @@ int ha_ndbcluster::complemented_read(const byte *old_data, byte *new_data,
    }
  }
  
  if (execute_no_commit(this,trans) != 0) 
  if (execute_no_commit(this,trans,false) != 0) 
  {
    table->status= STATUS_NOT_FOUND;
    DBUG_RETURN(ndb_err(trans));
@@ -1914,7 +1919,7 @@ int ha_ndbcluster::peek_indexed_rows(const byte *record)
  }
  last= trans->getLastDefinedOperation();
  if (first)
    res= execute_no_commit_ie(this,trans);
    res= execute_no_commit_ie(this,trans,false);
  else
  {
    // Table has no keys
@@ -1963,7 +1968,7 @@ int ha_ndbcluster::unique_index_read(const byte *key,
  if ((res= define_read_attrs(buf, op)))
    DBUG_RETURN(res);

  if (execute_no_commit_ie(this,trans) != 0) 
  if (execute_no_commit_ie(this,trans,false) != 0) 
  {
    table->status= STATUS_NOT_FOUND;
    DBUG_RETURN(ndb_err(trans));
@@ -2011,7 +2016,7 @@ inline int ha_ndbcluster::fetch_next(NdbScanOperation* cursor)
    */
    if (m_ops_pending && m_blobs_pending)
    {
      if (execute_no_commit(this,trans) != 0)
      if (execute_no_commit(this,trans,false) != 0)
        DBUG_RETURN(ndb_err(trans));
      m_ops_pending= 0;
      m_blobs_pending= FALSE;
@@ -2043,7 +2048,7 @@ inline int ha_ndbcluster::fetch_next(NdbScanOperation* cursor)
      {
        if (m_transaction_on)
        {
          if (execute_no_commit(this,trans) != 0)
          if (execute_no_commit(this,trans,false) != 0)
            DBUG_RETURN(-1);
        }
        else
@@ -2370,7 +2375,7 @@ int ha_ndbcluster::ordered_index_scan(const key_range *start_key,
      ERR_RETURN(trans->getNdbError());
  }

  if (execute_no_commit(this,trans) != 0)
  if (execute_no_commit(this,trans,false) != 0)
    DBUG_RETURN(ndb_err(trans));
  
  DBUG_RETURN(next_result(buf));
@@ -2440,7 +2445,7 @@ int ha_ndbcluster::full_table_scan(byte *buf)
  if ((res= define_read_attrs(buf, op)))
    DBUG_RETURN(res);

  if (execute_no_commit(this,trans) != 0)
  if (execute_no_commit(this,trans,false) != 0)
    DBUG_RETURN(ndb_err(trans));
  DBUG_PRINT("exit", ("Scan started successfully"));
  DBUG_RETURN(next_result(buf));
@@ -2605,7 +2610,7 @@ int ha_ndbcluster::write_row(byte *record)
    m_bulk_insert_not_flushed= FALSE;
    if (m_transaction_on)
    {
      if (execute_no_commit(this,trans) != 0)
      if (execute_no_commit(this,trans,false) != 0)
      {
        m_skip_auto_increment= TRUE;
        no_uncommitted_rows_execute_failure();
@@ -2841,7 +2846,7 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
    op->setValue(no_fields, part_func_value);
  }
  // Execute update operation
  if (!cursor && execute_no_commit(this,trans) != 0) {
  if (!cursor && execute_no_commit(this,trans,false) != 0) {
    no_uncommitted_rows_execute_failure();
    DBUG_RETURN(ndb_err(trans));
  }
@@ -2927,7 +2932,7 @@ int ha_ndbcluster::delete_row(const byte *record)
  }

  // Execute delete operation
  if (execute_no_commit(this,trans) != 0) {
  if (execute_no_commit(this,trans,false) != 0) {
    no_uncommitted_rows_execute_failure();
    DBUG_RETURN(ndb_err(trans));
  }
@@ -3391,6 +3396,26 @@ int ha_ndbcluster::close_scan()

  NdbScanOperation *cursor= m_active_cursor ? m_active_cursor : m_multi_cursor;
  
  if (m_lock_tuple)
  {
    /*
      Lock level m_lock.type either TL_WRITE_ALLOW_WRITE
      (SELECT FOR UPDATE) or TL_READ_WITH_SHARED_LOCKS (SELECT
      LOCK WITH SHARE MODE) and row was not explictly unlocked 
      with unlock_row() call
    */
      NdbOperation *op;
      // Lock row
      DBUG_PRINT("info", ("Keeping lock on scanned row"));
      
      if (!(op= cursor->lockCurrentTuple()))
      {
	m_lock_tuple= false;
	ERR_RETURN(trans->getNdbError());
      }
      m_ops_pending++;      
  }
  m_lock_tuple= false;
  if (m_ops_pending)
  {
    /*
@@ -3398,7 +3423,7 @@ int ha_ndbcluster::close_scan()
      deleteing/updating transaction before closing the scan    
    */
    DBUG_PRINT("info", ("ops_pending: %d", m_ops_pending));    
    if (execute_no_commit(this,trans) != 0) {
    if (execute_no_commit(this,trans,false) != 0) {
      no_uncommitted_rows_execute_failure();
      DBUG_RETURN(ndb_err(trans));
    }
@@ -3788,7 +3813,7 @@ int ha_ndbcluster::end_bulk_insert()
    m_bulk_insert_not_flushed= FALSE;
    if (m_transaction_on)
    {
      if (execute_no_commit(this, trans) != 0)
      if (execute_no_commit(this, trans,false) != 0)
      {
        no_uncommitted_rows_execute_failure();
        my_errno= error= ndb_err(trans);
@@ -3963,6 +3988,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type)
          ERR_RETURN(ndb->getNdbError());
        thd_ndb->init_open_tables();
        thd_ndb->stmt= trans;
	thd_ndb->query_state&= NDB_QUERY_NORMAL;
        trans_register_ha(thd, FALSE, &ndbcluster_hton);
      } 
      else 
@@ -3978,6 +4004,7 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type)
            ERR_RETURN(ndb->getNdbError());
          thd_ndb->init_open_tables();
          thd_ndb->all= trans; 
	  thd_ndb->query_state&= NDB_QUERY_NORMAL;
          trans_register_ha(thd, TRUE, &ndbcluster_hton);

          /*
@@ -4134,6 +4161,7 @@ int ha_ndbcluster::start_stmt(THD *thd, thr_lock_type lock_type)
    thd_ndb->stmt= trans;
    trans_register_ha(thd, FALSE, &ndbcluster_hton);
  }
  thd_ndb->query_state&= NDB_QUERY_NORMAL;
  m_active_trans= trans;

  // Start of statement
@@ -7560,6 +7588,7 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
  NDB_INDEX_TYPE index_type= get_index_type(active_index);
  ulong reclength= table_share->reclength;
  NdbOperation* op;
  Thd_ndb *thd_ndb= get_thd_ndb(current_thd);

  if (uses_blob_value())
  {
@@ -7573,7 +7602,7 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
                                                sorted, 
                                                buffer));
  }

  thd_ndb->query_state|= NDB_QUERY_MULTI_READ_RANGE;
  m_disable_multi_read= FALSE;

  /**
@@ -7745,7 +7774,7 @@ ha_ndbcluster::read_multi_range_first(KEY_MULTI_RANGE **found_range_p,
   */
  m_current_multi_operation= 
    lastOp ? lastOp->next() : m_active_trans->getFirstDefinedOperation();
  if (!(res= execute_no_commit_ie(this, m_active_trans)))
  if (!(res= execute_no_commit_ie(this, m_active_trans,true)))
  {
    m_multi_range_defined= multi_range_curr;
    multi_range_curr= ranges;
@@ -9543,6 +9572,24 @@ ha_ndbcluster::generate_scan_filter(Ndb_cond_stack *ndb_cond_stack,
  DBUG_RETURN(0);
}


void 
ha_ndbcluster::release_completed_operations(NdbTransaction *trans,
					    bool force_release)
{
  if (!force_release)
  {
    if (get_thd_ndb(current_thd)->query_state & NDB_QUERY_MULTI_READ_RANGE)
    {
      /* We are batching reads and have not consumed all fetched
	 rows yet, releasing operation records is unsafe 
      */
      return;
    }
  }
  trans->releaseCompletedOperations();
}

/*
  get table space info for SHOW CREATE TABLE
*/
+11 −2
Original line number Diff line number Diff line
@@ -534,6 +534,12 @@ class Ndb_cond_traverse_context
  Ndb_rewrite_context *rewrite_stack;
};


typedef enum ndb_query_state_bits {
  NDB_QUERY_NORMAL = 0,
  NDB_QUERY_MULTI_READ_RANGE = 1
} NDB_QUERY_STATE_BITS;

/*
  Place holder for ha_ndbcluster thread specific data
*/
@@ -571,6 +577,7 @@ class Thd_ndb
  int error;
  uint32 options;
  List<NDB_SHARE> changed_tables;
  uint query_state;
  HASH open_tables;
};

@@ -833,6 +840,8 @@ static void set_tabname(const char *pathname, char *tabname);
  void no_uncommitted_rows_update(int);
  void no_uncommitted_rows_reset(THD *);

  void release_completed_operations(NdbTransaction*, bool);

  /*
    Condition pushdown
  */
@@ -849,8 +858,8 @@ static void set_tabname(const char *pathname, char *tabname);

  friend int execute_commit(ha_ndbcluster*, NdbTransaction*);
  friend int execute_no_commit_ignore_no_key(ha_ndbcluster*, NdbTransaction*);
  friend int execute_no_commit(ha_ndbcluster*, NdbTransaction*);
  friend int execute_no_commit_ie(ha_ndbcluster*, NdbTransaction*);
  friend int execute_no_commit(ha_ndbcluster*, NdbTransaction*, bool);
  friend int execute_no_commit_ie(ha_ndbcluster*, NdbTransaction*, bool);

  NdbTransaction *m_active_trans;
  NdbScanOperation *m_active_cursor;
Loading