MXS-3143: Route FOUND_ROWS to last used target
This will cause the query to be routed to the same server where a possible SQL_CALC_FOUND_ROWS was executed.
This commit is contained in:
		@ -643,3 +643,16 @@ executed session command for the duration of the session. Applications that use
 | 
			
		||||
long-running sessions might cause MariaDB MaxScale to consume a growing amount
 | 
			
		||||
of memory unless the sessions are closed. This can be solved by adjusting the
 | 
			
		||||
value of `max_sescmd_history`.
 | 
			
		||||
 | 
			
		||||
### Routing to previous target
 | 
			
		||||
 | 
			
		||||
In the following cases, a query is routed to the same server where the previous
 | 
			
		||||
query was executed. If no previous target is found, the query is routed to the
 | 
			
		||||
current master.
 | 
			
		||||
 | 
			
		||||
* If a query uses the `FOUND_ROWS()` function, it will be routed to the server
 | 
			
		||||
  where the last query was executed. This is done with the assumption that a
 | 
			
		||||
  query with `SQL_CALC_FOUND_ROWS` was previously executed.
 | 
			
		||||
 | 
			
		||||
* COM_STMT_FETCH_ROWS will always be routed to the same server where the
 | 
			
		||||
  COM_STMT_EXECUTE was routed.
 | 
			
		||||
 | 
			
		||||
@ -1107,6 +1107,21 @@ QueryClassifier::RouteInfo QueryClassifier::update_route_info(
 | 
			
		||||
 | 
			
		||||
        process_routing_hints(pBuffer->hint, &route_target);
 | 
			
		||||
 | 
			
		||||
        if (route_target == TARGET_SLAVE)
 | 
			
		||||
        {
 | 
			
		||||
            const QC_FUNCTION_INFO* infos = nullptr;
 | 
			
		||||
            size_t n_infos = 0;
 | 
			
		||||
            qc_get_function_info(pBuffer, &infos, &n_infos);
 | 
			
		||||
 | 
			
		||||
            for (size_t i = 0; i < n_infos; ++i)
 | 
			
		||||
            {
 | 
			
		||||
                if (strcasecmp(infos[i].name, "FOUND_ROWS") == 0)
 | 
			
		||||
                {
 | 
			
		||||
                    route_target = TARGET_LAST_USED;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (session_trx_is_ending(m_pSession)
 | 
			
		||||
            || qc_query_is_type(type_mask, QUERY_TYPE_BEGIN_TRX))
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user