~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/atomics_test.cc

  • Committer: Stewart Smith
  • Date: 2010-08-12 16:48:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1707.
  • Revision ID: stewart@flamingspork.com-20100812164846-s9bhy47g60bvqs41
bug lp:611379 Equivalent queries with Impossible where return different results

The following two equivalent queries return different results in maria 5.2 and 5.3 (and identical results in mysql 5.5.5) :

SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` ;

SELECT * FROM ( SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` );

MariaDB returns 0 on the second query and NULL on the first, whereas MySQL returns NULL on both. In MariaDB, both EXPLAIN plans agree that "Impossible WHERE noticed after reading const tables"



We have some slightly different output in drizzle:

main.bug_lp611379 [ fail ]
drizzletest: At line 9: query 'explain select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a)
as t' failed: 1048: Column 'sum(distinct t1.a)' cannot be null

but the fix gets us the correct query results, although with slightly different execution plans.



This fix is directly ported from MariaDB.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
22
 
#define BOOST_TEST_DYN_LINK
23
 
#include <boost/test/unit_test.hpp>
 
21
#include "config.h"
 
22
 
 
23
#include <gtest/gtest.h>
24
24
 
25
25
#include <drizzled/atomics.h>
26
26
 
27
27
using namespace drizzled;
28
28
 
29
 
BOOST_AUTO_TEST_SUITE(AtomicOperations)
30
 
BOOST_AUTO_TEST_CASE(fetch_and_store)
31
 
{
32
 
  atomic<uint32_t> u235;
33
 
 
34
 
  BOOST_REQUIRE_EQUAL(0, u235.fetch_and_store(1));
35
 
 
36
 
  u235.fetch_and_store(15);
37
 
 
38
 
  BOOST_REQUIRE_EQUAL(15, u235.fetch_and_store(100));
39
 
  BOOST_REQUIRE_EQUAL(100, u235);
40
 
}
41
 
 
42
 
BOOST_AUTO_TEST_CASE(fetch_and_increment)
43
 
{
44
 
  atomic<uint32_t> u235;
45
 
 
46
 
  BOOST_REQUIRE_EQUAL(0, u235.fetch_and_increment());
47
 
  BOOST_REQUIRE_EQUAL(1, u235);
48
 
}
49
 
 
50
 
BOOST_AUTO_TEST_CASE(fetch_and_add)
51
 
{
52
 
  atomic<uint32_t> u235;
53
 
 
54
 
  BOOST_REQUIRE_EQUAL(0, u235.fetch_and_add(2));
55
 
  BOOST_REQUIRE_EQUAL(2, u235);
56
 
}
57
 
 
58
 
BOOST_AUTO_TEST_CASE(add_and_fetch)
59
 
{
60
 
  atomic<uint32_t> u235;
61
 
 
62
 
  BOOST_REQUIRE_EQUAL(10, u235.add_and_fetch(10));
63
 
  BOOST_REQUIRE_EQUAL(10, u235);
64
 
}
65
 
 
66
 
BOOST_AUTO_TEST_CASE(fetch_and_decrement)
67
 
{
68
 
  atomic<uint32_t> u235;
69
 
 
70
 
  u235.fetch_and_store(15);
71
 
 
72
 
  BOOST_REQUIRE_EQUAL(15, u235.fetch_and_decrement());
73
 
  BOOST_REQUIRE_EQUAL(14, u235);
74
 
}
75
 
 
76
 
BOOST_AUTO_TEST_CASE(compare_and_swap)
 
29
TEST(atomic_operations, fetch_and_store)
 
30
{
 
31
  atomic<uint32_t> u235;
 
32
 
 
33
  EXPECT_EQ(0, u235.fetch_and_store(1));
 
34
 
 
35
  u235.fetch_and_store(15);
 
36
 
 
37
  EXPECT_EQ(15, u235.fetch_and_store(100));
 
38
  EXPECT_EQ(100, u235);
 
39
}
 
40
 
 
41
TEST(atomic_operations, fetch_and_increment)
 
42
{
 
43
  atomic<uint32_t> u235;
 
44
 
 
45
  EXPECT_EQ(0, u235.fetch_and_increment());
 
46
  EXPECT_EQ(1, u235);
 
47
}
 
48
 
 
49
TEST(atomic_operations, fetch_and_add)
 
50
{
 
51
  atomic<uint32_t> u235;
 
52
 
 
53
  EXPECT_EQ(0, u235.fetch_and_add(2));
 
54
  EXPECT_EQ(2, u235);
 
55
}
 
56
 
 
57
TEST(atomic_operations, add_and_fetch)
 
58
{
 
59
  atomic<uint32_t> u235;
 
60
 
 
61
  EXPECT_EQ(10, u235.add_and_fetch(10));
 
62
  EXPECT_EQ(10, u235);
 
63
}
 
64
 
 
65
TEST(atomic_operations, fetch_and_decrement)
 
66
{
 
67
  atomic<uint32_t> u235;
 
68
 
 
69
  u235.fetch_and_store(15);
 
70
 
 
71
  EXPECT_EQ(15, u235.fetch_and_decrement());
 
72
  EXPECT_EQ(14, u235);
 
73
}
 
74
 
 
75
TEST(atomic_operations, compare_and_swap)
77
76
{
78
77
  atomic<uint32_t> u235;
79
78
 
80
79
  u235.fetch_and_store(100);
81
80
 
82
 
  BOOST_REQUIRE(not u235.compare_and_swap(42, 200));
83
 
  BOOST_REQUIRE(u235.compare_and_swap(200, 100));
84
 
  BOOST_REQUIRE_EQUAL(200, u235);
85
 
}
86
 
 
87
 
BOOST_AUTO_TEST_CASE(increment)
88
 
{
89
 
  atomic<uint32_t> u235;
90
 
  u235.fetch_and_store(200);
91
 
  BOOST_REQUIRE_EQUAL(201, u235.increment());
92
 
}
93
 
 
94
 
BOOST_AUTO_TEST_CASE(decrement)
95
 
{
96
 
  atomic<uint32_t> u235;
97
 
  u235.fetch_and_store(200);
98
 
 
99
 
  BOOST_REQUIRE_EQUAL(199, u235.decrement());
100
 
}
101
 
 
102
 
BOOST_AUTO_TEST_SUITE_END()
103
 
 
104
 
/* TODO: add tests for += and -= when supported */
 
81
  EXPECT_EQ(false, u235.compare_and_swap(42, 200));
 
82
  EXPECT_EQ(true, u235.compare_and_swap(200, 100));
 
83
  EXPECT_EQ(200, u235);
 
84
}
 
85
 
 
86
TEST(atomic_operations, increment)
 
87
{
 
88
  atomic<uint32_t> u235;
 
89
  u235.fetch_and_store(200);
 
90
  EXPECT_EQ(201, u235.increment());
 
91
}
 
92
 
 
93
TEST(atomic_operations, decrement)
 
94
{
 
95
  atomic<uint32_t> u235;
 
96
  u235.fetch_and_store(200);
 
97
 
 
98
  EXPECT_EQ(199, u235.decrement());
 
99
}
 
100
 
 
101
/*
 
102
TEST(atomic_operations, increment_assign)
 
103
{
 
104
  atomic<uint32_t> u235;
 
105
  u235.fetch_and_store(200);
 
106
 
 
107
  EXPECT_EQ(242, u235+=42);
 
108
}
 
109
 
 
110
TEST(atomic_operations, decrement_assign)
 
111
{
 
112
  atomic<uint32_t> u235;
 
113
  u235.fetch_and_store(200);
 
114
 
 
115
  EXPECT_EQ(158, u235-=42);
 
116
}
 
117
*/
 
118
 
105
119