--- orig/rw-splitting.lua 2007-09-06 16:41:10.000000000 +0100 +++ new/rw-splitting.lua 2008-08-15 00:44:39.000000000 +0100 @@ -220,13 +220,14 @@ -- print("token: " .. token.token_name) -- print(" val: " .. token.text) - if not is_in_select_calc_found_rows and token.token_name == "TK_SQL_SQL_CALC_FOUND_ROWS" then + if not is_in_select_calc_found_rows and (token.token_name == "TK_SQL_SQL_CALC_FOUND_ROWS" or (token.token_name == "TK_FUNCTION" and token.text:upper() == "FOUND_ROWS")) then is_in_select_calc_found_rows = true + elseif not is_insert_id and token.token_name == "TK_FUNCTION" and token.text:upper() == "LAST_INSERT_ID" then + is_insert_id = true elseif not is_insert_id and token.token_name == "TK_LITERAL" then local utext = token.text:upper() - if utext == "LAST_INSERT_ID" or - utext == "@@INSERT_ID" then + if utext == "@@INSERT_ID" then is_insert_id = true end end @@ -239,14 +240,15 @@ -- if we ask for the last-insert-id we have to ask it on the original -- connection - if not is_insert_id then + if is_insert_id then + print(" found a SELECT LAST_INSERT_ID(), going to master") + elseif is_in_select_calc_found_rows then + print(" need to calculate the rows, going to master") + else -- neither of these two, pick an idle slave local backend_ndx = lb.idle_ro() - if backend_ndx > 0 then proxy.connection.backend_ndx = backend_ndx end - else - print(" found a SELECT LAST_INSERT_ID(), staying on the same backend") end end end