Show
added a comment - I found the original error occurs when I set QueryTimeout=1 with CONNECT table to a view on SQL server.
It didn't occur with QueryTimeout=20.
I assume this solves the problem,I will also check in the original environment.
Thank you for the fix.
On SQL server
CREATE VIEW heavy_view
AS SELECT
CASE WHEN MAX(t3.charge) <> 0 THEN MIN(t2.order_no) / 3.14 ELSE 0 END AS ROW1
,CASE WHEN MAX(t3.charge) <> 0 THEN MIN(t2.customer_no) / 3.14 ELSE 0 END AS ROW2
,CASE WHEN MAX(t3.charge) <> 0 THEN MIN(t2.order_method) / 3.14 ELSE 0 END AS ROW3
,CASE WHEN MAX(t3.charge) <> 0 THEN MIN(t2.pay_method) / 3.14 ELSE 0 END AS ROW4
,CASE WHEN MAX(t3.charge) <> 0 THEN MAX(t2.order_no) / 3.14 ELSE 0 END AS ROW5
,CASE WHEN MAX(t3.charge) <> 0 THEN MAX(t2.customer_no) / 3.14 ELSE 0 END AS ROW6
,CASE WHEN MAX(t3.charge) <> 0 THEN MAX(t2.order_method) / 3.14 ELSE 0 END AS ROW7
,CASE WHEN MAX(t3.charge) <> 0 THEN MAX(t2.pay_method) / 3.14 ELSE 0 END AS ROW8
,CASE WHEN MAX(t3.charge) <> 0 THEN 2 * MIN(t2.order_no) + 2 * MIN(t2.order_no) ELSE 0 END AS ROW9
,CASE WHEN MAX(t3.charge) <> 0 THEN 2 * MIN(t2.customer_no) + 2 * MIN(t2.order_no) ELSE 0 END AS ROW10
,CASE WHEN MAX(t3.charge) <> 0 THEN 2 * MIN(t2.order_method) + 2 * MIN(t2.order_no) ELSE 0 END AS ROW11
,CASE WHEN MAX(t3.charge) <> 0 THEN 2 * MIN(t2.pay_method) + 2 * MIN(t2.order_no) ELSE 0 END AS ROW12
,CASE WHEN MAX(t3.charge) <> 0 THEN 2 * MAX(t2.order_no) + 2 * MIN(t2.order_no) ELSE 0 END AS ROW13
,CASE WHEN MAX(t3.charge) <> 0 THEN 2 * MAX(t2.customer_no) + 2 * MIN(t2.order_no) ELSE 0 END AS ROW14
,CASE WHEN MAX(t3.charge) <> 0 THEN 2 * MAX(t2.order_method) + 2 * MIN(t2.order_no) ELSE 0 END AS ROW15
,CASE WHEN MAX(t3.charge) <> 0 THEN 2 * MAX(t2.pay_method) + 2 * MIN(t2.order_no) ELSE 0 END AS ROW16
FROM wrk_dmi_vCustomer t1
LEFT JOIN dmi_vHeader t2 ON t1.customer_no = t2.customer_no
LEFT JOIN dmi_vDelivery t3 ON t2.order_no = t3.order_no
GROUP BY t1.customer_no ,t1.post_code,t2.order_madia,t2.pay_method ,t2.coupon_no,t3.charge;
On MariaDB 10.0.16
[root@kc1060 ~]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 56
Server version: 10.0.16-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use test;
No connection. Trying to reconnect...
Connection id: 57
Current database: *** NONE ***
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [test]> CREATE OR REPLACE TABLE `ms_heavy_view`
-> ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=nlj_original;UID=SYSTEMDMI;pwd=H0geFuga' `table_type`=ODBC `block_size`=1 `tabname`='heavy_view';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 58
Current database: test
Query OK, 0 rows affected (0.08 sec)
MariaDB [test]> SELECT * FROM ms_heavy_view LIMIT 0,1;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 59
Current database: test
+-------------+------------+----------+----------+--------------+------------+----------+----------+-------+-------+-------+-------+--------+-------+-------+-------+
| ROW1 | ROW2 | ROW3 | ROW4 | ROW5 | ROW6 | ROW7 | ROW8 | ROW9 | ROW10 | ROW11 | ROW12 | ROW13 | ROW14 | ROW15 | ROW16 |
+-------------+------------+----------+----------+--------------+------------+----------+----------+-------+-------+-------+-------+--------+-------+-------+-------+
| 4975.159235 | 318.152866 | 0.318471 | 0.636942 | 11642.356687 | 318.152866 | 0.318471 | 0.636942 | 62488 | 33242 | 31246 | 31248 | 104358 | 33242 | 31246 | 31248 |
+-------------+------------+----------+----------+--------------+------------+----------+----------+-------+-------+-------+-------+--------+-------+-------+-------+
1 row in set (3.40 sec)
MariaDB [test]> CREATE OR REPLACE TABLE `ms_heavy_view_1`
-> ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=nlj_original;UID=SYSTEMDMI;pwd=H0geFuga' `table_type`=ODBC `block_size`=1 `tabname`='heavy_view' OPTION_LIST='QueryTimeout=1,ConnectTimeout=1';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 60
Current database: test
Query OK, 0 rows affected (0.08 sec)
MariaDB [test]> SELECT * FROM ms_heavy_view_1 LIMIT 0,1;
ERROR 1296 (HY000): Got error 174 '[unixODBC][Microsoft][ODBC Driver 11 for SQL Server]Query timeout expired' from CONNECT
MariaDB [test]> CREATE OR REPLACE TABLE `ms_heavy_view_20`
-> ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=nlj_original;UID=SYSTEMDMI;pwd=H0geFuga' `table_type`=ODBC `block_size`=1 `tabname`='heavy_view' OPTION_LIST='QueryTimeout=20,ConnectTimeout=20';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 61
Current database: test
Query OK, 0 rows affected (0.08 sec)
MariaDB [test]> SELECT * FROM ms_heavy_view_20 LIMIT 0,1;
+-------------+------------+----------+----------+--------------+------------+----------+----------+-------+-------+-------+-------+--------+-------+-------+-------+
| ROW1 | ROW2 | ROW3 | ROW4 | ROW5 | ROW6 | ROW7 | ROW8 | ROW9 | ROW10 | ROW11 | ROW12 | ROW13 | ROW14 | ROW15 | ROW16 |
+-------------+------------+----------+----------+--------------+------------+----------+----------+-------+-------+-------+-------+--------+-------+-------+-------+
| 4975.159235 | 318.152866 | 0.318471 | 0.636942 | 11642.356687 | 318.152866 | 0.318471 | 0.636942 | 62488 | 33242 | 31246 | 31248 | 104358 | 33242 | 31246 | 31248 |
+-------------+------------+----------+----------+--------------+------------+----------+----------+-------+-------+-------+-------+--------+-------+-------+-------+
1 row in set (3.39 sec)
MariaDB [test]> CREATE OR REPLACE TABLE `ms_heavy_view_20v1`
-> ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=nlj_original;UID=SYSTEMDMI;pwd=H0geFuga' `table_type`=ODBC `block_size`=1 `tabname`='heavy_view' OPTION_LIST='QueryTimeout=20,ConnectTimeout=1';
Query OK, 0 rows affected (0.07 sec)
MariaDB [test]> SELECT * FROM ms_heavy_view_20v1 LIMIT 0,1;
+-------------+------------+----------+----------+--------------+------------+----------+----------+-------+-------+-------+-------+--------+-------+-------+-------+
| ROW1 | ROW2 | ROW3 | ROW4 | ROW5 | ROW6 | ROW7 | ROW8 | ROW9 | ROW10 | ROW11 | ROW12 | ROW13 | ROW14 | ROW15 | ROW16 |
+-------------+------------+----------+----------+--------------+------------+----------+----------+-------+-------+-------+-------+--------+-------+-------+-------+
| 4975.159235 | 318.152866 | 0.318471 | 0.636942 | 11642.356687 | 318.152866 | 0.318471 | 0.636942 | 62488 | 33242 | 31246 | 31248 | 104358 | 33242 | 31246 | 31248 |
+-------------+------------+----------+----------+--------------+------------+----------+----------+-------+-------+-------+-------+--------+-------+-------+-------+
1 row in set (3.40 sec)
MariaDB [test]> CREATE OR REPLACE TABLE `ms_heavy_view_20v2`
-> ENGINE=CONNECT DEFAULT CHARSET=utf8 CONNECTION='DSN=nlj_original;UID=SYSTEMDMI;pwd=H0geFuga' `table_type`=ODBC `block_size`=1 `tabname`='heavy_view' OPTION_LIST='QueryTimeout=1,ConnectTimeout=20';
Query OK, 0 rows affected (0.07 sec)
MariaDB [test]> SELECT * FROM ms_heavy_view_20v2 LIMIT 0,1;
ERROR 1296 (HY000): Got error 174 '[unixODBC][Microsoft][ODBC Driver 11 for SQL Server]Query timeout expired' from CONNECT
Did you try to use QueryTimeout option in odbc.ini?
I am not an expert at ODBC, but the quick search suggests that there is at least an option with this name, so possibly it will work.