|
1 |
| -/* Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. |
| 1 | +/* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 2 |
|
3 | 3 | This program is free software; you can redistribute it and/or modify
|
4 | 4 | it under the terms of the GNU General Public License as published by
|
@@ -380,6 +380,15 @@ static bool mysql_ha_open_table(THD *thd, TABLE_LIST *hash_tables)
|
380 | 380 | */
|
381 | 381 | hash_tables->table->open_by_handler= 1;
|
382 | 382 |
|
| 383 | + /* |
| 384 | + Generated column expressions have been resolved using the MEM_ROOT of the |
| 385 | + current HANDLER statement, which is cleared when the statement has finished. |
| 386 | + Clean up the expressions so that subsequent HANDLER ... READ calls don't |
| 387 | + access data allocated on a cleared MEM_ROOT. The generated column |
| 388 | + expressions have to be re-resolved on each HANDLER ... READ call. |
| 389 | + */ |
| 390 | + hash_tables->table->cleanup_gc_items(); |
| 391 | + |
383 | 392 | DBUG_PRINT("exit",("OK"));
|
384 | 393 | DBUG_RETURN(FALSE);
|
385 | 394 | }
|
@@ -679,6 +688,14 @@ bool Sql_cmd_handler_read::execute(THD *thd)
|
679 | 688 |
|
680 | 689 | table->file->init_table_handle_for_HANDLER();
|
681 | 690 |
|
| 691 | + /* |
| 692 | + Resolve the generated column expressions. They have to be cleaned up before |
| 693 | + returning, since the resolved expressions may point to memory allocated on |
| 694 | + the MEM_ROOT of the current HANDLER ... READ statement, which will be |
| 695 | + cleared when the statement has completed. |
| 696 | + */ |
| 697 | + if (table->refix_gc_items(thd)) goto err; |
| 698 | + |
682 | 699 | for (num_rows=0; num_rows < select_limit_cnt; )
|
683 | 700 | {
|
684 | 701 | switch (mode) {
|
@@ -843,13 +860,15 @@ bool Sql_cmd_handler_read::execute(THD *thd)
|
843 | 860 | trans_commit_stmt(thd);
|
844 | 861 | mysql_unlock_tables(thd,lock);
|
845 | 862 | thd->mdl_context.rollback_to_savepoint(mdl_savepoint);
|
| 863 | + table->cleanup_gc_items(); |
846 | 864 | my_eof(thd);
|
847 | 865 | DBUG_PRINT("exit",("OK"));
|
848 | 866 | DBUG_RETURN(FALSE);
|
849 | 867 |
|
850 | 868 | err:
|
851 | 869 | trans_rollback_stmt(thd);
|
852 | 870 | mysql_unlock_tables(thd,lock);
|
| 871 | + table->cleanup_gc_items(); |
853 | 872 | err1:
|
854 | 873 | thd->mdl_context.rollback_to_savepoint(mdl_savepoint);
|
855 | 874 | err0:
|
|
0 commit comments