您好,登錄后才能下訂單哦!
MySQL 8.0 Query Rewrite支持SELECT INSERT UPDETE DELETE REPLACE語句重寫
這個(gè)功能要點(diǎn)贊,比如開發(fā)上線時(shí),有個(gè)SQL查詢字段索引忘記加了,直接把線上CPU打滿,此時(shí),你可以將SQL重寫,讓業(yè)務(wù)先報(bào)錯(cuò),別打死數(shù)據(jù)庫,然后馬上通知開發(fā)回滾,等加完索引后再上線。
安裝插件
mysql?-S?/tmp/mysql_hcy.sock?-p123456?<./install_rewriter.sql
查看是否生效
SHOW?GLOBAL?VARIABLES?LIKE?'rewriter_enabled';
編寫重寫規(guī)則
insert?into?query_rewrite.rewrite_rules(pattern,?replacement,? pattern_database)?values?( "SELECT?*?from?sbtest1?limit??", "SELECT?k,c?from?sbtest1?limit??", "test");
意思為:
將以下語句
SELECT * from sbtest1 limit ?;
改寫成:
SELECT k,c from sbtest1 limit ?;
注:?jiǎn)柼?hào)?為變量
執(zhí)行規(guī)則生效
CALL?query_rewrite.flush_rewrite_rules();
演示
mysql>?SELECT?*?from?sbtest1?limit?1\G; ***************************?1.?row?*************************** k:?499284 c:?83868641912-28773972837-60736120486-75162659906-27563526494-20381887404-41576422241-93426793964-56405065102-33518432330 1?row?in?set,?1?warning?(0.00?sec) ? ERROR:? No?query?specified ? mysql>?show?warnings\G ***************************?1.?row?*************************** ??Level:?Note ???Code:?1105 Message:?Query?'SELECT?*?from?sbtest1?limit?1'?rewritten?to?'SELECT?k,c?from?sbtest1?limit?1'?by?a?query?rewrite?plugin 1?row?in?set?(0.00?sec)
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。