null+****@clear*****
null+****@clear*****
2012年 1月 23日 (月) 19:12:26 JST
Kouhei Sutou 2012-01-23 19:12:26 +0900 (Mon, 23 Jan 2012)
New Revision: e387e9c8eb8950ddb692ff6409dc4db733fe958d
Log:
[storage] support double value in multiple column index. refs #1212
Added files:
test/sql/suite/mroonga_storage/r/multiple_column_index_double.result
test/sql/suite/mroonga_storage/t/multiple_column_index_double.test
Modified files:
ha_mroonga.cc
Modified: ha_mroonga.cc (+10 -6)
===================================================================
--- ha_mroonga.cc 2012-01-23 19:04:44 +0900 (68b43ba)
+++ ha_mroonga.cc 2012-01-23 19:12:26 +0900 (111b9f1)
@@ -1337,21 +1337,25 @@ static uchar *mrn_multiple_column_key_encode(KEY *key_info,
mrn_byte_order_host_to_network(current_buffer, &int_value, data_size);
if (decode) {
int_value = *((int *)current_buffer);
- *((int *)current_buffer) = int_value ^ (((int_value ^ (1 << n_bits)) >> n_bits) | (1 << n_bits));
+ *((int *)current_buffer) =
+ int_value ^ (((int_value ^ (1 << n_bits)) >> n_bits) |
+ (1 << n_bits));
}
}
break;
case TYPE_DOUBLE:
{
- long_long_value = (long long int)(double_value);
+ int n_bits = (data_size * 8 - 1);
+ long_long_value = *((long long int *)(&double_value));
if (!decode)
- long_long_value ^= ((long_long_value >> 63) | (1LL << 63));
+ long_long_value ^= ((long_long_value >> n_bits) | (1LL << n_bits));
mrn_byte_order_host_to_network(current_buffer, &long_long_value,
data_size);
if (decode) {
- *((long long int *)current_buffer) ^= (1LL << 63);
- *((long long int *)current_buffer) ^=
- (*((long long int *)current_buffer) >> 63);
+ long_long_value = *((long long int *)current_buffer);
+ *((long long int *)current_buffer) =
+ long_long_value ^ (((long_long_value ^ (1LL << n_bits)) >> n_bits) |
+ (1LL << n_bits));
}
}
break;
Added: test/sql/suite/mroonga_storage/r/multiple_column_index_double.result (+28 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/r/multiple_column_index_double.result 2012-01-23 19:12:26 +0900 (c75733f)
@@ -0,0 +1,28 @@
+DROP TABLE IF EXISTS temperatures;
+CREATE TABLE temperatures (
+id INT PRIMARY KEY AUTO_INCREMENT,
+title VARCHAR(20),
+temperature DOUBLE,
+KEY temperature_index(temperature),
+KEY multi_index(temperature, title)
+);
+INSERT INTO temperatures VALUES (NULL, "Hot!", 28.2);
+INSERT INTO temperatures VALUES (NULL, "Snow!", -2.8);
+INSERT INTO temperatures VALUES (NULL, "Rainy!", 12.7);
+SELECT temperature FROM temperatures WHERE temperature BETWEEN 10 AND 30;
+temperature
+12.7
+28.2
+SELECT temperature FROM temperatures WHERE temperature BETWEEN -10 AND 20;
+temperature
+-2.8
+12.7
+SELECT title, temperature FROM temperatures WHERE temperature BETWEEN 10 AND 30;
+title temperature
+Rainy! 12.7
+Hot! 28.2
+SELECT title, temperature FROM temperatures WHERE temperature BETWEEN -10 AND 20;
+title temperature
+Snow! -2.8
+Rainy! 12.7
+DROP TABLE temperatures;
Added: test/sql/suite/mroonga_storage/t/multiple_column_index_double.test (+43 -0) 100644
===================================================================
--- /dev/null
+++ test/sql/suite/mroonga_storage/t/multiple_column_index_double.test 2012-01-23 19:12:26 +0900 (a94b23f)
@@ -0,0 +1,43 @@
+# Copyright(C) 2012 Kouhei Sutou <kou****@clear*****>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+--source include/have_mroonga.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS temperatures;
+--enable_warnings
+
+CREATE TABLE temperatures (
+ id INT PRIMARY KEY AUTO_INCREMENT,
+ title VARCHAR(20),
+ temperature DOUBLE,
+ KEY temperature_index(temperature),
+ KEY multi_index(temperature, title)
+);
+
+INSERT INTO temperatures VALUES (NULL, "Hot!", 28.2);
+INSERT INTO temperatures VALUES (NULL, "Snow!", -2.8);
+INSERT INTO temperatures VALUES (NULL, "Rainy!", 12.7);
+
+SELECT temperature FROM temperatures WHERE temperature BETWEEN 10 AND 30;
+SELECT temperature FROM temperatures WHERE temperature BETWEEN -10 AND 20;
+
+SELECT title, temperature FROM temperatures WHERE temperature BETWEEN 10 AND 30;
+SELECT title, temperature FROM temperatures WHERE temperature BETWEEN -10 AND 20;
+
+DROP TABLE temperatures;
+
+--source include/have_mroonga_deinit.inc