[Commits] Rev 3498: MDEV-494, part #1: phantom row for big full-scan selects in file:///data0/psergey/dev2/5.5-cassandra-r01/

Sergey Petrunya psergey at askmonty.org
Tue Aug 28 19:22:46 EEST 2012


At file:///data0/psergey/dev2/5.5-cassandra-r01/

------------------------------------------------------------
revno: 3498
revision-id: psergey at askmonty.org-20120828162245-rwodocdqhk30fb11
parent: psergey at askmonty.org-20120828085333-b8fk493v8wvczu5b
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: 5.5-cassandra-r01
timestamp: Tue 2012-08-28 20:22:45 +0400
message:
  MDEV-494, part #1: phantom row for big full-scan selects
  - Full table scan internally uses LIMIT n, and re-starts the scan from
    the last seen rowkey value.  rowkey ranges are inclusive, so we will
    see the same rowkey again. We should ignore it.
=== modified file 'mysql-test/r/cassandra.result'
--- a/mysql-test/r/cassandra.result	2012-08-28 08:53:33 +0000
+++ b/mysql-test/r/cassandra.result	2012-08-28 16:22:45 +0000
@@ -166,3 +166,20 @@
 select * from t1;
 rowkey	a
 drop table t1;
+#
+# MDEV-494, part #1: phantom row for big full-scan selects
+#
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+CREATE TABLE t1 (rowkey BIGINT PRIMARY KEY, a BIGINT) ENGINE=CASSANDRA
+thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf2';
+insert into t1 select A.a + 10 * B.a + 100*C.a, 12345 from t0 A, t0 B, t0 C;
+select count(*) from t1;
+count(*)
+1000
+select count(*) from t1 where a=12345;
+count(*)
+1000
+delete from t1;
+drop table t1;
+drop table t0;

=== modified file 'mysql-test/t/cassandra.test'
--- a/mysql-test/t/cassandra.test	2012-08-28 08:53:33 +0000
+++ b/mysql-test/t/cassandra.test	2012-08-28 16:22:45 +0000
@@ -172,6 +172,23 @@
 select * from t1;
 drop table t1;
  
+--echo #
+--echo # MDEV-494, part #1: phantom row for big full-scan selects
+--echo #
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+CREATE TABLE t1 (rowkey BIGINT PRIMARY KEY, a BIGINT) ENGINE=CASSANDRA
+  thrift_host='localhost' keyspace='mariadbtest2' column_family = 'cf2';
+
+insert into t1 select A.a + 10 * B.a + 100*C.a, 12345 from t0 A, t0 B, t0 C;
+
+select count(*) from t1;
+select count(*) from t1 where a=12345;
+
+delete from t1;
+drop table t1;
+drop table t0;
 ############################################################################
 ## Cassandra cleanup
 ############################################################################

=== modified file 'storage/cassandra/cassandra_se.cc'
--- a/storage/cassandra/cassandra_se.cc	2012-08-27 04:44:58 +0000
+++ b/storage/cassandra/cassandra_se.cc	2012-08-28 16:22:45 +0000
@@ -93,6 +93,10 @@
   void get_read_rowkey(char **value, int *value_len);
 
   /* Reads, multi-row scans */
+private:
+  bool have_rowkey_to_skip;
+  std::string rowkey_to_skip;
+public:
   bool get_range_slices(bool last_key_as_start_key);
   void finish_reading_range_slices();
   bool get_next_range_slice_row(bool *eof);
@@ -106,15 +110,17 @@
   int  add_lookup_key(const char *key, size_t key_len);
   bool multiget_slice();
 
+private:
   std::vector<std::string> mrr_keys; /* TODO: can we use allocator to put them onto MRR buffer? */
   std::map<std::string, std::vector<ColumnOrSuperColumn> > mrr_result;
   std::map<std::string, std::vector<ColumnOrSuperColumn> >::iterator mrr_result_it;
-
+public:
   bool get_next_multiget_row();
 
   bool truncate();
   bool remove_row();
 
+private:
   /* Non-inherited utility functions: */
   int64_t get_i64_timestamp();
 };
@@ -407,9 +413,17 @@
   key_range.__isset.end_key= true;
 
   if (last_key_as_start_key)
+  {
     key_range.start_key= rowkey;
+
+    have_rowkey_to_skip= true;
+    rowkey_to_skip= rowkey;
+  }
   else
+  {
+    have_rowkey_to_skip= false;
     key_range.start_key.assign("", 0);
+  }
 
   key_range.end_key.assign("", 0);
   key_range.count= read_batch_size;
@@ -441,6 +455,7 @@
 /* Switch to next row. This may produce an error */
 bool Cassandra_se_impl::get_next_range_slice_row(bool *eof)
 {
+restart:
   if (key_slice_it == key_slice_vec.end())
   {
     if (get_slices_returned_less)
@@ -462,7 +477,13 @@
       return false;
     }
   }
- 
+  
+  if (have_rowkey_to_skip && !rowkey_to_skip.compare(key_slice_it->key))
+  {
+    key_slice_it++;
+    goto restart;
+  }
+
   *eof= false;
   column_data_vec= key_slice_it->columns;
   rowkey= key_slice_it->key;



More information about the commits mailing list