~ubuntu-branches/ubuntu/natty/mysql-5.1/natty-proposed

« back to all changes in this revision

Viewing changes to mysql-test/suite/innodb/t/innodb_bug30423.test

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 08:30:45 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120222083045-2rd53r4bnyx7qus4
Tags: 5.1.61-0ubuntu0.11.04.1
* SECURITY UPDATE: Update to 5.1.61 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2011-2262
  - CVE-2012-0075
  - CVE-2012-0112
  - CVE-2012-0113
  - CVE-2012-0114
  - CVE-2012-0115
  - CVE-2012-0116
  - CVE-2012-0117
  - CVE-2012-0118
  - CVE-2012-0119
  - CVE-2012-0120
  - CVE-2012-0484
  - CVE-2012-0485
  - CVE-2012-0486
  - CVE-2012-0487
  - CVE-2012-0488
  - CVE-2012-0489
  - CVE-2012-0490
  - CVE-2012-0491
  - CVE-2012-0492
  - CVE-2012-0493
  - CVE-2012-0494
  - CVE-2012-0495
  - CVE-2012-0496

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Test for Bug #30423, InnoDBs treatment of NULL in index stats causes
 
2
# bad "rows examined" estimates.
 
3
# Implemented InnoDB system variable "innodb_stats_method" with
 
4
# "nulls_equal" (default), "nulls_unequal", and "nulls_ignored" options.
 
5
 
 
6
-- source include/have_innodb.inc
 
7
 
 
8
let $innodb_stats_method_orig = `select @@innodb_stats_method`;
 
9
 
 
10
# default setting for innodb_stats_method is "nulls_equal"
 
11
set global innodb_stats_method = default;
 
12
 
 
13
select @@innodb_stats_method;
 
14
 
 
15
# create three tables, bug30243_1, bug30243_2 and bug30243_3.
 
16
# The test scenario is adopted from original bug #30423 report.
 
17
# table bug30243_1 and bug30243_3 have many NULL values
 
18
 
 
19
-- disable_result_log
 
20
-- disable_query_log
 
21
 
 
22
DROP TABLE IF EXISTS bug30243_1;
 
23
CREATE TABLE bug30243_1 (
 
24
  org_id int(11) NOT NULL default '0',
 
25
  UNIQUE KEY (org_id)
 
26
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
27
 
 
28
LOCK TABLES bug30243_1 WRITE;
 
29
INSERT INTO bug30243_1 VALUES (11),(15),(16),(17),(19),(20),(21),(23),(24),
 
30
(25),(26),(27),(28),(29),(30),(31),(32),(33),(34),(35),(37),(38),(40),(41),
 
31
(42),(43),(44),(45),(46),(47),(48),(49),(50),(51),(52),(53),(54),(55),(56),
 
32
(57),(58),(59),(60),(61),(62),(63),(64),(65),(66),(67),(68),(69),(70),(71),
 
33
(72),(73),(74),(75),(76),(77),(78),(79),(80),(81),(82),(83),(84),(85),(86),
 
34
(87),(88),(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101),
 
35
(102),(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114),
 
36
(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126),(127),
 
37
(128),(129),(130),(131),(132),(133),(134),(135),(136),(137),(138),(139),(140),
 
38
(141),(142),(143),(144),(145);
 
39
UNLOCK TABLES;
 
40
 
 
41
DROP TABLE IF EXISTS bug30243_3;
 
42
CREATE TABLE bug30243_3 (
 
43
  org_id int(11) default NULL,
 
44
  KEY (org_id)
 
45
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
46
 
 
47
INSERT INTO bug30243_3 VALUES (NULL);
 
48
 
 
49
begin;
 
50
let $i=14;
 
51
while ($i)
 
52
{
 
53
        INSERT INTO bug30243_3 SELECT NULL FROM bug30243_3;
 
54
        dec $i;
 
55
}
 
56
 
 
57
INSERT INTO bug30243_3 VALUES (34),(34),(35),(56),(58),(62),(62),(64),(65),(66),(80),(135),(137),(138),(139),(140),(142),(143),(144),(145);
 
58
commit;
 
59
 
 
60
DROP TABLE IF EXISTS bug30243_2;
 
61
CREATE TABLE bug30243_2 (
 
62
  org_id int(11) default NULL,
 
63
  KEY `contacts$org_id` (org_id)
 
64
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
65
 
 
66
INSERT INTO bug30243_2 VALUES (NULL);
 
67
 
 
68
begin;
 
69
let $i=16;
 
70
while ($i)
 
71
{
 
72
        INSERT INTO bug30243_2 SELECT NULL FROM bug30243_2;
 
73
        dec $i;
 
74
}
 
75
 
 
76
INSERT INTO bug30243_2 VALUES (11),(15),(16),(17),(20),(21),(23),(24),(25),
 
77
(26),(27),(28),(29),(30),(31),(32),(33),(34),(37),(38),(40),(41),(42),(43),
 
78
(44),(45),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
 
79
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
 
80
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
 
81
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
 
82
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),
 
83
(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(46),(48),
 
84
(48),(50),(51),(52),(52),(53),(54),(55),(57),(60),(61),(62),(62),(62),(62),
 
85
(62),(63),(64),(64),(65),(66),(66),(67),(68),(69),(70),(71),(72),(73),(74),
 
86
(75),(76),(77),(78),(79),(80),(80),(81),(82),(83),(84),(85),(86),(87),(88),
 
87
(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101),(102),
 
88
(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114),
 
89
(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126),
 
90
(127),(128),(129),(130),(131),(132),(133),(133),(135),(135),(135),(135),
 
91
(136),(136),(138),(138),(139),(139),(139),(140),(141),(141),(142),(143),
 
92
(143),(145),(145);
 
93
commit;
 
94
 
 
95
 
 
96
-- enable_result_log
 
97
-- enable_query_log
 
98
 
 
99
# check tables's value
 
100
select count(*) from bug30243_3 where org_id is not NULL;
 
101
select count(*) from bug30243_3 where org_id is NULL;
 
102
 
 
103
select count(*) from bug30243_2 where org_id is not NULL;
 
104
select count(*) from bug30243_2 where org_id is NULL;
 
105
 
 
106
select @@innodb_stats_method;
 
107
 
 
108
analyze table bug30243_1;
 
109
analyze table bug30243_2;
 
110
analyze table bug30243_3;
 
111
 
 
112
# Following query plan shows that we over estimate the rows per
 
113
# unique value (since there are many NULLs).
 
114
# Skip this query log since the stats estimate could vary from runs
 
115
-- disable_query_log
 
116
-- disable_result_log
 
117
explain SELECT COUNT(*), 0
 
118
        FROM bug30243_1 orgs
 
119
        LEFT JOIN bug30243_3 sa_opportunities
 
120
                ON orgs.org_id=sa_opportunities.org_id
 
121
        LEFT JOIN bug30243_2 contacts
 
122
                ON orgs.org_id=contacts.org_id ;
 
123
-- enable_query_log
 
124
-- enable_result_log
 
125
 
 
126
# following set operation will fail
 
127
#--error ER_WRONG_VALUE_FOR_VAR
 
128
--error 1231
 
129
set global innodb_stats_method = "NULL";
 
130
 
 
131
set global innodb_stats_method = "nulls_ignored";
 
132
 
 
133
select @@innodb_stats_method;
 
134
 
 
135
# Regenerate the stats with "nulls_ignored" option
 
136
 
 
137
analyze table bug30243_1;
 
138
analyze table bug30243_2;
 
139
analyze table bug30243_3;
 
140
 
 
141
# Following query plan shows that we get the correct rows per
 
142
# unique value (should be approximately 1 row per value)
 
143
explain SELECT COUNT(*), 0
 
144
        FROM bug30243_1 orgs
 
145
        LEFT JOIN bug30243_3 sa_opportunities
 
146
                ON orgs.org_id=sa_opportunities.org_id
 
147
        LEFT JOIN bug30243_2 contacts
 
148
                ON orgs.org_id=contacts.org_id ;
 
149
 
 
150
select @@innodb_stats_method;
 
151
 
 
152
# Try the "nulls_unequal" option
 
153
set global innodb_stats_method = "nulls_unequal";
 
154
 
 
155
select @@innodb_stats_method;
 
156
 
 
157
analyze table bug30243_1;
 
158
analyze table bug30243_2;
 
159
analyze table bug30243_3;
 
160
 
 
161
# Following query plan shows that we get the correct rows per
 
162
# unique value (~1)
 
163
explain SELECT COUNT(*), 0
 
164
        FROM bug30243_1 orgs
 
165
        LEFT JOIN bug30243_3 sa_opportunities
 
166
                ON orgs.org_id=sa_opportunities.org_id
 
167
        LEFT JOIN bug30243_2 contacts
 
168
                ON orgs.org_id=contacts.org_id;
 
169
 
 
170
 
 
171
# Create a table with all NULL values, make sure the stats calculation
 
172
# does not crash with table of all NULL values
 
173
-- disable_query_log
 
174
CREATE TABLE table_bug30423 (
 
175
  org_id int(11) default NULL,
 
176
  KEY(org_id)
 
177
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
178
 
 
179
INSERT INTO `table_bug30423` VALUES (NULL);
 
180
 
 
181
begin;
 
182
let $i=10;
 
183
while ($i)
 
184
{
 
185
        INSERT INTO table_bug30423 SELECT NULL FROM table_bug30423;
 
186
        dec $i;
 
187
}
 
188
commit;
 
189
 
 
190
-- enable_query_log
 
191
 
 
192
SELECT COUNT(*) FROM table_bug30423 WHERE org_id IS NULL;
 
193
 
 
194
# calculate the statistics for the table for "nulls_ignored" and
 
195
# "nulls_unequal" option
 
196
set global innodb_stats_method = "nulls_unequal";
 
197
analyze table table_bug30423;
 
198
 
 
199
set global innodb_stats_method = "nulls_ignored";
 
200
analyze table table_bug30423;
 
201
 
 
202
 
 
203
eval set global innodb_stats_method = $innodb_stats_method_orig;
 
204
 
 
205
drop table bug30243_2;
 
206
 
 
207
drop table bug30243_1;
 
208
 
 
209
drop table bug30243_3;
 
210
 
 
211
drop table table_bug30423;