Skip to content

Commit 78e067e

Browse files
author
Kailasnath Nagarkar
committed
Bug #27659490 : SELECT USING DYNAMIC RANGE AND INDEX
MERGE USE TOO MUCH MEMORY(OOM) Issue: While creating a handler object, index-merge access creates it in statement MEM_ROOT. However when this is used with "Dynamic range access method", as range optimizer gets invoked multiple times, mysql ends up consuming a lot of memory. Solution: Instead of using statement MEM_ROOT to allocate the handler object, use the local MEM_ROOT of the range optimizer which gets destroyed at the end of range optimizer's usage.
1 parent c1b3d63 commit 78e067e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

sql/opt_range.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights
1+
/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights
22
* reserved.
33
44
This program is free software; you can redistribute it and/or modify
@@ -1660,7 +1660,18 @@ int QUICK_ROR_UNION_SELECT::reset()
16601660
List_iterator_fast<QUICK_SELECT_I> it(quick_selects);
16611661
while ((quick= it++))
16621662
{
1663-
if (quick->init_ror_merged_scan(FALSE))
1663+
/*
1664+
Use mem_root of this "QUICK" as using the statement mem_root
1665+
might result in too many allocations when combined with
1666+
dynamic range access where range optimizer is invoked many times
1667+
for a single statement.
1668+
*/
1669+
THD *thd= quick->head->in_use;
1670+
MEM_ROOT *saved_root= thd->mem_root;
1671+
thd->mem_root= &alloc;
1672+
error= quick->init_ror_merged_scan(false);
1673+
thd->mem_root= saved_root;
1674+
if (error)
16641675
DBUG_RETURN(1);
16651676
}
16661677
scans_inited= TRUE;

0 commit comments

Comments
 (0)