File: regress-mariadb

package info (click to toggle)
postgresql-mysql-fdw 2.5.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 512 kB
  • sloc: ansic: 3,477; sql: 618; sh: 48; makefile: 42
file content (297 lines) | stat: -rw-r--r-- 12,960 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
--- /dev/null
+++ b/expected/connection_validation_1.out
@@ -0,0 +1,59 @@
+\set MYSQL_HOST			'\'localhost\''
+\set MYSQL_PORT			'\'3306\''
+\set MYSQL_USER_NAME	'\'edb\''
+\set MYSQL_PASS			'\'edb\''
+-- Before running this file User must create database mysql_fdw_regress on
+-- MySQL with all permission for 'edb' user with 'edb' password and ran
+-- mysql_init.sh file to create tables.
+\c contrib_regression
+CREATE EXTENSION IF NOT EXISTS mysql_fdw;
+CREATE SERVER mysql_svr FOREIGN DATA WRAPPER mysql_fdw
+  OPTIONS (host :MYSQL_HOST, port :MYSQL_PORT);
+CREATE USER MAPPING FOR public SERVER mysql_svr
+  OPTIONS (username :MYSQL_USER_NAME, password :MYSQL_PASS);
+-- Create foreign table and Validate
+CREATE FOREIGN TABLE f_mysql_test(a int, b int)
+  SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'mysql_test');
+SELECT * FROM f_mysql_test ORDER BY 1, 2;
+ a | b 
+---+---
+ 1 | 1
+(1 row)
+
+-- FDW-121: After a change to a pg_foreign_server or pg_user_mapping catalog
+-- entry, existing connection should be invalidated and should make new
+-- connection using the updated connection details.
+-- Alter SERVER option.
+-- Set wrong host, subsequent operation on this server should use updated
+-- details and fail as the host address is not correct.
+ALTER SERVER mysql_svr OPTIONS (SET host 'localhos');
+SELECT * FROM f_mysql_test ORDER BY 1, 2;
+ERROR:  failed to connect to MySQL: Unknown MySQL server host 'localhos' (-2)
+-- Set the correct host-name, next operation should succeed.
+ALTER SERVER mysql_svr OPTIONS (SET host :MYSQL_HOST);
+SELECT * FROM f_mysql_test ORDER BY 1, 2;
+ a | b 
+---+---
+ 1 | 1
+(1 row)
+
+-- Alter USER MAPPING option.
+-- Set wrong user-name and password, next operation should fail.
+ALTER USER MAPPING FOR PUBLIC SERVER mysql_svr
+  OPTIONS (SET username 'foo1', SET password 'bar1');
+SELECT * FROM f_mysql_test ORDER BY 1, 2;
+ERROR:  failed to connect to MySQL: Access denied for user 'foo1'@'localhost' (using password: YES)
+-- Set correct user-name and password, next operation should succeed.
+ALTER USER MAPPING FOR PUBLIC SERVER mysql_svr
+  OPTIONS (SET username :MYSQL_USER_NAME, SET password :MYSQL_PASS);
+SELECT * FROM f_mysql_test ORDER BY 1, 2;
+ a | b 
+---+---
+ 1 | 1
+(1 row)
+
+-- Cleanup
+DROP FOREIGN TABLE f_mysql_test;
+DROP USER MAPPING FOR public SERVER mysql_svr;
+DROP SERVER mysql_svr;
+DROP EXTENSION mysql_fdw;
--- /dev/null
+++ b/expected/dml_1.out
@@ -0,0 +1,232 @@
+\set MYSQL_HOST			'\'localhost\''
+\set MYSQL_PORT			'\'3306\''
+\set MYSQL_USER_NAME	'\'edb\''
+\set MYSQL_PASS			'\'edb\''
+-- Before running this file User must create database mysql_fdw_regress on
+-- MySQL with all permission for 'edb' user with 'edb' password and ran
+-- mysql_init.sh file to create tables.
+\c contrib_regression
+CREATE EXTENSION IF NOT EXISTS mysql_fdw;
+CREATE SERVER mysql_svr FOREIGN DATA WRAPPER mysql_fdw
+  OPTIONS (host :MYSQL_HOST, port :MYSQL_PORT);
+CREATE USER MAPPING FOR public SERVER mysql_svr
+  OPTIONS (username :MYSQL_USER_NAME, password :MYSQL_PASS);
+-- Create foreign tables
+CREATE FOREIGN TABLE f_mysql_test(a int, b int)
+  SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'mysql_test');
+CREATE FOREIGN TABLE fdw126_ft1(stu_id int, stu_name varchar(255), stu_dept int)
+  SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress1', table_name 'student');
+CREATE FOREIGN TABLE fdw126_ft2(stu_id int, stu_name varchar(255))
+  SERVER mysql_svr OPTIONS (table_name 'student');
+CREATE FOREIGN TABLE fdw126_ft3(a int, b varchar(255))
+  SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress1', table_name 'numbers');
+CREATE FOREIGN TABLE fdw126_ft4(a int, b varchar(255))
+  SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress1', table_name 'nosuchtable');
+CREATE FOREIGN TABLE fdw126_ft5(a int, b varchar(255))
+  SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress2', table_name 'numbers');
+CREATE FOREIGN TABLE fdw126_ft6(stu_id int, stu_name varchar(255))
+  SERVER mysql_svr OPTIONS (table_name 'mysql_fdw_regress1.student');
+CREATE FOREIGN TABLE f_empdata(emp_id int, emp_dat bytea)
+  SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress', table_name 'empdata');
+CREATE FOREIGN TABLE fdw193_ft1(stu_id varchar(10), stu_name varchar(255), stu_dept int)
+  SERVER mysql_svr OPTIONS (dbname 'mysql_fdw_regress1', table_name 'student1');
+-- Operation on blob data.
+INSERT INTO f_empdata VALUES (1, decode ('01234567', 'hex'));
+SELECT count(*) FROM f_empdata ORDER BY 1;
+ count 
+-------
+     1
+(1 row)
+
+SELECT emp_id, emp_dat FROM f_empdata ORDER BY 1;
+ emp_id |  emp_dat   
+--------+------------
+      1 | \x01234567
+(1 row)
+
+UPDATE f_empdata SET emp_dat = decode ('0123', 'hex');
+SELECT emp_id, emp_dat FROM f_empdata ORDER BY 1;
+ emp_id | emp_dat 
+--------+---------
+      1 | \x0123
+(1 row)
+
+-- FDW-126: Insert/update/delete statement failing in mysql_fdw by picking
+-- wrong database name.
+-- Verify the INSERT/UPDATE/DELETE operations on another foreign table which
+-- resides in the another database in MySQL.  The previous commands performs
+-- the operation on foreign table created for tables in mysql_fdw_regress
+-- MySQL database.  Below operations will be performed for foreign table
+-- created for table in mysql_fdw_regress1 MySQL database.
+INSERT INTO fdw126_ft1 VALUES(1, 'One', 101);
+UPDATE fdw126_ft1 SET stu_name = 'one' WHERE stu_id = 1;
+DELETE FROM fdw126_ft1 WHERE stu_id = 1;
+-- Select on f_mysql_test foreign table which is created for mysql_test table
+-- from mysql_fdw_regress MySQL database.  This call is just to cross verify if
+-- everything is working correctly.
+SELECT a, b FROM f_mysql_test ORDER BY 1, 2;
+ a | b 
+---+---
+ 1 | 1
+(1 row)
+
+-- Insert into fdw126_ft2 table which does not have dbname specified while
+-- creating the foreign table, so it will consider the schema name of foreign
+-- table as database name and try to connect/lookup into that database.  Will
+-- throw an error.
+INSERT INTO fdw126_ft2 VALUES(2, 'Two');
+ERROR:  failed to execute the MySQL query: 
+Unknown database 'public'
+-- Check with the same table name from different database. fdw126_ft3 is
+-- pointing to the mysql_fdw_regress1.numbers and not mysql_fdw_regress.numbers
+-- table.  INSERT/UPDATE/DELETE should be failing.  SELECT will return no rows.
+INSERT INTO fdw126_ft3 VALUES(1, 'One');
+ERROR:  first column of remote table must be unique for INSERT/UPDATE/DELETE operation
+SELECT a, b FROM fdw126_ft3 ORDER BY 1, 2 LIMIT 1;
+ a | b 
+---+---
+(0 rows)
+
+UPDATE fdw126_ft3 SET b = 'one' WHERE a = 1;
+ERROR:  first column of remote table must be unique for INSERT/UPDATE/DELETE operation
+DELETE FROM fdw126_ft3 WHERE a = 1;
+ERROR:  first column of remote table must be unique for INSERT/UPDATE/DELETE operation
+-- Check when table_name is given in database.table form in foreign table
+-- should error out as syntax error
+INSERT INTO fdw126_ft6 VALUES(1, 'One');
+ERROR:  failed to execute the MySQL query: 
+You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.student' at line 1
+-- Perform the ANALYZE on the foreign table which is not present on the remote
+-- side.  Should not crash.
+-- The database is present but not the target table.
+ANALYZE fdw126_ft4;
+ERROR:  relation mysql_fdw_regress1.nosuchtable does not exist
+-- The database itself is not present.
+ANALYZE fdw126_ft5;
+ERROR:  relation mysql_fdw_regress2.numbers does not exist
+-- Some other variant of analyze and vacuum.
+-- when table exists, should give skip-warning
+VACUUM f_empdata;
+WARNING:  skipping "f_empdata" --- cannot vacuum non-tables or special system tables
+VACUUM FULL f_empdata;
+WARNING:  skipping "f_empdata" --- cannot vacuum non-tables or special system tables
+VACUUM FREEZE f_empdata;
+WARNING:  skipping "f_empdata" --- cannot vacuum non-tables or special system tables
+ANALYZE f_empdata;
+WARNING:  skipping "f_empdata" --- cannot analyze this foreign table
+ANALYZE f_empdata(emp_id);
+WARNING:  skipping "f_empdata" --- cannot analyze this foreign table
+VACUUM ANALYZE f_empdata;
+WARNING:  skipping "f_empdata" --- cannot vacuum non-tables or special system tables
+-- Verify the before update trigger which modifies the column value which is not
+-- part of update statement.
+CREATE FUNCTION before_row_update_func() RETURNS TRIGGER AS $$
+BEGIN
+  NEW.stu_name := NEW.stu_name || ' trigger updated!';
+	RETURN NEW;
+  END
+$$ language plpgsql;
+CREATE TRIGGER before_row_update_trig
+BEFORE UPDATE ON fdw126_ft1
+FOR EACH ROW EXECUTE PROCEDURE before_row_update_func();
+INSERT INTO fdw126_ft1 VALUES(1, 'One', 101);
+EXPLAIN (verbose, costs off)
+UPDATE fdw126_ft1 SET stu_dept = 201 WHERE stu_id = 1;
+                                                             QUERY PLAN                                                              
+-------------------------------------------------------------------------------------------------------------------------------------
+ Update on public.fdw126_ft1
+   ->  Foreign Scan on public.fdw126_ft1
+         Output: stu_id, stu_name, 201, stu_id, fdw126_ft1.*
+         Local server startup cost: 10
+         Remote query: SELECT `stu_id`, `stu_name`, `stu_dept` FROM `mysql_fdw_regress1`.`student` WHERE ((`stu_id` = 1)) FOR UPDATE
+(5 rows)
+
+UPDATE fdw126_ft1 SET stu_dept = 201 WHERE stu_id = 1;
+SELECT * FROM fdw126_ft1 ORDER BY stu_id;
+ stu_id |       stu_name       | stu_dept 
+--------+----------------------+----------
+      1 | One trigger updated! |      201
+(1 row)
+
+-- Throw an error when target list has row identifier column.
+UPDATE fdw126_ft1 SET stu_dept = 201, stu_id = 10  WHERE stu_id = 1;
+ERROR:  row identifier column update is not supported
+-- Throw an error when before row update trigger modify the row identifier
+-- column (int column) value.
+CREATE OR REPLACE FUNCTION before_row_update_func() RETURNS TRIGGER AS $$
+BEGIN
+  NEW.stu_name := NEW.stu_name || ' trigger updated!';
+  NEW.stu_id = 20;
+  RETURN NEW;
+  END
+$$ language plpgsql;
+UPDATE fdw126_ft1 SET stu_dept = 301 WHERE stu_id = 1;
+ERROR:  row identifier column update is not supported
+-- Verify the before update trigger which modifies the column value which is
+-- not part of update statement.
+CREATE OR REPLACE FUNCTION before_row_update_func() RETURNS TRIGGER AS $$
+BEGIN
+  NEW.stu_name := NEW.stu_name || ' trigger updated!';
+  RETURN NEW;
+  END
+$$ language plpgsql;
+CREATE TRIGGER before_row_update_trig1
+BEFORE UPDATE ON fdw193_ft1
+FOR EACH ROW EXECUTE PROCEDURE before_row_update_func();
+INSERT INTO fdw193_ft1 VALUES('aa', 'One', 101);
+EXPLAIN (verbose, costs off)
+UPDATE fdw193_ft1 SET stu_dept = 201 WHERE stu_id = 'aa';
+                                                               QUERY PLAN                                                                
+-----------------------------------------------------------------------------------------------------------------------------------------
+ Update on public.fdw193_ft1
+   ->  Foreign Scan on public.fdw193_ft1
+         Output: stu_id, stu_name, 201, stu_id, fdw193_ft1.*
+         Local server startup cost: 10
+         Remote query: SELECT `stu_id`, `stu_name`, `stu_dept` FROM `mysql_fdw_regress1`.`student1` WHERE ((`stu_id` = 'aa')) FOR UPDATE
+(5 rows)
+
+UPDATE fdw193_ft1 SET stu_dept = 201 WHERE stu_id = 'aa';
+SELECT * FROM fdw193_ft1 ORDER BY stu_id;
+ stu_id |       stu_name       | stu_dept 
+--------+----------------------+----------
+ aa     | One trigger updated! |      201
+(1 row)
+
+-- Throw an error when before row update trigger modify the row identifier
+-- column (varchar column) value.
+CREATE OR REPLACE FUNCTION before_row_update_func() RETURNS TRIGGER AS $$
+BEGIN
+  NEW.stu_name := NEW.stu_name || ' trigger updated!';
+  NEW.stu_id = 'bb';
+  RETURN NEW;
+  END
+$$ language plpgsql;
+UPDATE fdw193_ft1 SET stu_dept = 301 WHERE stu_id = 'aa';
+ERROR:  row identifier column update is not supported
+-- Verify the NULL assignment scenario.
+CREATE OR REPLACE FUNCTION before_row_update_func() RETURNS TRIGGER AS $$
+BEGIN
+  NEW.stu_name := NEW.stu_name || ' trigger updated!';
+  NEW.stu_id = NULL;
+  RETURN NEW;
+  END
+$$ language plpgsql;
+UPDATE fdw193_ft1 SET stu_dept = 401 WHERE stu_id = 'aa';
+ERROR:  row identifier column update is not supported
+-- Cleanup
+DELETE FROM fdw126_ft1;
+DELETE FROM f_empdata;
+DELETE FROM fdw193_ft1;
+DROP FOREIGN TABLE f_mysql_test;
+DROP FOREIGN TABLE fdw126_ft1;
+DROP FOREIGN TABLE fdw126_ft2;
+DROP FOREIGN TABLE fdw126_ft3;
+DROP FOREIGN TABLE fdw126_ft4;
+DROP FOREIGN TABLE fdw126_ft5;
+DROP FOREIGN TABLE fdw126_ft6;
+DROP FOREIGN TABLE f_empdata;
+DROP FOREIGN TABLE fdw193_ft1;
+DROP FUNCTION before_row_update_func();
+DROP USER MAPPING FOR public SERVER mysql_svr;
+DROP SERVER mysql_svr;
+DROP EXTENSION mysql_fdw;