~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/derived.test

mergeĀ mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Initialize
2
 
--disable_warnings
3
2
drop table if exists t1,t2,t3;
4
 
--enable_warnings
5
3
 
6
4
select * from (select 2) b;
7
5
-- error 1054
17
15
CREATE TABLE t3 (a int not null, b char (10) not null);
18
16
insert into t3 values (3,'f'),(4,'y'),(5,'z'),(6,'c');
19
17
select t1.a,t4.y from t1,(select t2.a as y from t2,(select t3.b from t3 where t3.a>3) as t5  where t2.b=t5.b) as t4  where t1.a = t4.y;
20
 
--error ER_BAD_FIELD_ERROR
 
18
--error 1054
21
19
SELECT a FROM (SELECT 1 FROM (SELECT 1) a HAVING a=1) b;
22
 
--error ER_NON_UNIQ_ERROR
 
20
--error 1052
23
21
SELECT a,b as a FROM (SELECT '1' as a,'2' as b) b  HAVING a=1;
24
22
SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=2;
25
23
SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=1;
26
 
--error ER_BAD_FIELD_ERROR
 
24
--error 1054
27
25
SELECT 1 FROM (SELECT 1) a WHERE a=2;
28
 
--error ER_BAD_FIELD_ERROR
 
26
--error 1054
29
27
SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1  HAVING a=1) as a;
30
 
--sort_result
31
28
select * from t1 as x1, (select * from t1) as x2;
32
29
explain select * from t1 as x1, (select * from t1) as x2;
33
30
drop table if exists  t2,t3;
47
44
drop table t1, t2;
48
45
create table t1(a int not null, t char(8), index(a));
49
46
disable_query_log;
50
 
begin;
51
47
let $1 = 10000;
52
48
while ($1)
53
49
 {
54
50
  eval insert into t1 values ($1,'$1'); 
55
51
  dec $1;
56
52
 }
57
 
commit;
58
53
enable_query_log;
59
54
SELECT * FROM (SELECT * FROM t1) as b ORDER BY a  ASC LIMIT 0,20;
60
55
--replace_column 9 X
62
57
drop table t1;
63
58
SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b;
64
59
select * from (select 1 as a) b  left join (select 2 as a) c using(a);
65
 
--error ER_BAD_FIELD_ERROR
 
60
--error 1054
66
61
SELECT * FROM (SELECT 1 UNION SELECT a) b;
67
 
--error ER_BAD_FIELD_ERROR
 
62
--error 1054
68
63
SELECT 1 as a FROM (SELECT a UNION SELECT 1) b;
69
 
--error ER_BAD_FIELD_ERROR
 
64
--error 1054
70
65
SELECT 1 as a FROM (SELECT 1 UNION SELECT a) b;
71
 
--error ER_BAD_FIELD_ERROR
 
66
--error 1054
72
67
select 1 from  (select 2) a order by 0;
73
68
 
74
69
#
105
100
#
106
101
create table t1 (a int);
107
102
insert into t1 values (1),(2),(3);
 
103
-- error 1288
 
104
update (select * from t1) as t1 set a = 5;
108
105
-- error 1064
109
106
delete from (select * from t1);
110
107
-- error 1064
117
114
create table t1 (E1 INTEGER NOT NULL, E2 INTEGER NOT NULL, E3 INTEGER NOT NULL, PRIMARY KEY(E1)
118
115
);
119
116
insert into t1 VALUES(1,1,1), (2,2,1);
120
 
--sort_result
121
117
select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2;
122
118
explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2;
123
119
drop table t1;
124
120
 
125
121
create table t1 (a int);
126
122
insert into t1 values (1),(2);
127
 
--sort_result
128
123
select * from ( select * from t1 union select * from t1) a,(select * from t1 union select * from t1) b;
129
124
explain select * from ( select * from t1 union select * from t1) a,(select * from t1 union select * from t1) b;
130
125
drop table t1;
131
126
 
132
127
#
 
128
# multi-update & multi-delete with derived tables
 
129
#
 
130
CREATE TABLE `t1` (
 
131
  `N` int NOT NULL default '0',
 
132
  `M` int default '0'
 
133
) ENGINE=MyISAM;
 
134
INSERT INTO `t1` (N, M) VALUES (1, 0),(1, 0),(1, 0),(2, 0),(2, 0),(3, 0);
 
135
UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2;
 
136
select * from t1;
 
137
-- error 1288
 
138
# TODO: Bug lp:311109
 
139
#UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2, P2.N = 2;
 
140
-- error 1054
 
141
UPDATE `t1` AS P1 INNER JOIN (SELECT aaaa FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2;
 
142
delete P1.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
 
143
select * from t1;
 
144
--replace_result P2 p2
 
145
# TODO: Bug lp:311111
 
146
#--error ER_NON_UPDATABLE_TABLE
 
147
#delete P1.*,P2.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
 
148
-- error 1054
 
149
delete P1.* from `t1` AS P1 INNER JOIN (SELECT aaa FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N;
 
150
drop table t1;
 
151
 
 
152
#
133
153
# correct lex->current_select
134
154
#
135
 
CREATE TEMPORARY TABLE t1 (
 
155
CREATE TABLE t1 (
136
156
  OBJECTID int NOT NULL default 0,
137
157
  SORTORDER int NOT NULL auto_increment,
138
158
  KEY t1_SortIndex (SORTORDER),
139
159
  KEY t1_IdIndex (OBJECTID)
140
160
) ENGINE=MyISAM;
141
 
CREATE TEMPORARY TABLE t2 (
 
161
CREATE TABLE t2 (
142
162
  ID int default NULL,
143
163
  PARID int default NULL,
144
164
  UNIQUE KEY t2_ID_IDX (ID),
145
165
  KEY t2_PARID_IDX (PARID)
146
166
) engine=MyISAM;
147
167
INSERT INTO t2 VALUES (1000,0),(1001,0),(1002,0),(1003,0),(1008,1),(1009,1),(1010,1),(1011,1),(1016,2);
148
 
CREATE TEMPORARY TABLE t3 (
 
168
CREATE TABLE t3 (
149
169
  ID int default NULL,
150
170
  DATA decimal(10,2) default NULL,
151
171
  UNIQUE KEY t3_ID_IDX (ID)
200
220
#
201
221
CREATE TABLE t1 (a char(10), b char(10));
202
222
INSERT INTO t1 VALUES ('root','localhost'), ('root','%');
203
 
--error ER_SUBQUERY_NO_1_ROW
 
223
--error 1242
204
224
SELECT * FROM (SELECT (SELECT a.a FROM t1 AS a WHERE a.a = b.a) FROM t1 AS b) AS c;
205
225
DROP TABLE t1;
206
226
#