Skip to content

Zeroplex 生活隨筆

軟體開發、伺服器和生活瑣事

小 縮小字型大小。 中 重設字型大小。 大 放大字型大小。

SQL Server Linked Database insert 前會先 select

Posted on 2021 年 9 月 16 日2021 年 9 月 16 日 By 日落 在〈SQL Server Linked Database insert 前會先 select〉中尚無留言

苦主的主機自從在 SQL Server 跑 store procedure,透過 Linked Database 的方式把資料複製到 MySQL 以後,發現費用大為增加,開啟了 general query log 才發現在 insert into 之前還有詭異的行為:

312 Query	SELECT @@transaction_isolation
312 Query	set @@max_execution_time=600000
312 Query	set @@sql_select_limit=DEFAULT
312 Query	SELECT * FROM report.test
312 Init DB	report
312 Query	select database()
312 Query	set @@max_execution_time=600000
312 Prepare	insert into  report.test (s) values ("123")

有發現嗎?在第 4 行有個 SELECT,而且沒有任何 where 條件:會把整個 table 的資料全部拉回去。當好這張表就是放統計資料,所以流量就反應在帳單上了。


原本以為是 SQL Server 拉資料回去來分析 table schema,可惜不是。

針對 SQL Server 的 MSDASQL 和 MySQL ODBC Connecter 的設定做測試,發現 SQL Server 會自動使用 information_schema 來分析 table schema,若從 ODBC 把 filter 掉 information_schema 的後,SQL Server 會顯示出錯誤的資料。

目前大概只能把問題縮小到 SQL Server 上,但仍舊不明所以。若有遇到這類的問題只能盡量 workaround 掉了。

Tags:MSSQL

文章導覽

Previous Post: Windows 10 Start Menu Sucks
Next Post: 駭客軍團之 tar 指令

發佈留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *


其他

關於我  (About me)

小額贊助

  文章 RSS Feed

  留言 RSS Feed

Apache AWS Bash C/C++ Docker FreeBSD GCP Git Google Java JavaScript Laravel Linux Microsoft MSSQL MySQL Nginx PHP PHPUnit PostgreSQL Python Qt Ubuntu Unix Vim Web Windows WordPress XD 作業系統 分享 好站推薦 專題 攝影 新奇搞笑 新聞 旅遊 生活雜記 程式設計 網路架站 網頁設計 資訊學習 資訊安全 遊戲 音樂


創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權.