LoginSignup
0
0

More than 5 years have passed since last update.

空文字と文字列が共存するカラムを正規表現置換するとMysqlが落ちた件への対応。

Last updated at Posted at 2018-12-28

環境

Mysql: 8.0.13

テーブルのマスキングをしたかった

name
山田

↓こうしたい

name
山XX

空文字と文字列が共存するカラムに正規表現置換を行った。


UPDATE table
SET
  name = REGEXP_REPLACE(name, '^(.{1})(.*)', '$1XX');

エラーでMysqlが落ちた。

mysql     | terminate called after throwing an instance of 'std::out_of_range'
mysql     |   what():  basic_string::at: __n (which is 0) >= this->size() (which is 0)
mysql     | 05:46:54 UTC - mysqld got signal 6 ;
mysql     | This could be because you hit a bug. It is also possible that this binary
mysql     | or one of the libraries it was linked against is corrupt, improperly built,
mysql     | or misconfigured. This error can also be caused by malfunctioning hardware.
mysql     | Attempting to collect some information that could help diagnose the problem.
mysql     | As this is a crash and something is definitely wrong, the information
mysql     | collection process might fail.
mysql     | 
mysql     | key_buffer_size=8388608
mysql     | read_buffer_size=131072
mysql     | max_used_connections=1
mysql     | max_threads=151
mysql     | thread_count=2
mysql     | connection_count=1
mysql     | It is possible that mysqld could use up to 
mysql     | key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 67846 K  bytes of memory
mysql     | Hope that's ok; if not, decrease some variables in the equation.
mysql     | 
mysql     | Thread pointer: 0x7fe424000b50
mysql     | Attempting backtrace. You can use the following information to find out
mysql     | where mysqld died. If you see no messages after this, something went
mysql     | terribly wrong...
mysql     | stack_bottom = 7fe47c13cdc0 thread_stack 0x46000
mysql     | /usr/sbin/mysqld(my_print_stacktrace(unsigned char*, unsigned long)+0x2e) [0x55a417fadade]
mysql     | /usr/sbin/mysqld(handle_fatal_signal+0x4c1) [0x55a41721f171]
mysql     | /lib/x86_64-linux-gnu/libpthread.so.0(+0x110c0) [0x7fe491b420c0]
mysql     | /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcf) [0x7fe48fdd7fff]
mysql     | /lib/x86_64-linux-gnu/libc.so.6(abort+0x16a) [0x7fe48fdd942a]
mysql     | /usr/lib/x86_64-linux-gnu/libstdc++.so.6(__gnu_cxx::__verbose_terminate_handler()+0x15d) [0x7fe4906f00ad]
mysql     | /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8f066) [0x7fe4906ee066]
mysql     | /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8f0b1) [0x7fe4906ee0b1]
mysql     | /usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0x8f2c9) [0x7fe4906ee2c9]
mysql     | /usr/lib/x86_64-linux-gnu/libstdc++.so.6(std::__throw_out_of_range_fmt(char const*, ...)+0xf5) [0x7fe490716b85]
mysql     | /usr/sbin/mysqld(+0x107c6ed) [0x55a41747d6ed]
mysql     | /usr/sbin/mysqld(regexp::Regexp_engine::AppendTail()+0x15) [0x55a41747dab5]
mysql     | /usr/sbin/mysqld(regexp::Regexp_engine::Replace(std::__cxx11::basic_string<char16_t, std::char_traits<char16_t>, std::allocator<char16_t> > const&, int, int)+0x11d) [0x55a41747dc4d]
mysql     | /usr/sbin/mysqld(regexp::Regexp_facade::Replace(Item*, Item*, long, int, String*)+0xbe) [0x55a41747e99e]
mysql     | /usr/sbin/mysqld(Item_func_regexp_replace::val_str(String*)+0xd2) [0x55a4173c9c62]
mysql     | /usr/sbin/mysqld(Item::save_in_field_inner(Field*, bool)+0x7e) [0x55a41733db8e]
mysql     | /usr/sbin/mysqld(Item::save_in_field(Field*, bool)+0x44) [0x55a417355e34]
mysql     | /usr/sbin/mysqld(fill_record(THD*, TABLE*, List<Item>&, List<Item>&, MY_BITMAP*, MY_BITMAP*)+0xe1) [0x55a4170aa221]
mysql     | /usr/sbin/mysqld(fill_record_n_invoke_before_triggers(THD*, COPY_INFO*, List<Item>&, List<Item>&, TABLE*, enum_trigger_event_type, int)+0x1fd) [0x55a4170aa53d]
mysql     | /usr/sbin/mysqld(Sql_cmd_update::update_single_table(THD*)+0x1498) [0x55a4171c39b8]
mysql     | /usr/sbin/mysqld(Sql_cmd_dml::execute(THD*)+0x2d2) [0x55a41715daf2]
mysql     | /usr/sbin/mysqld(mysql_execute_command(THD*, bool)+0x2531) [0x55a41710df41]
mysql     | /usr/sbin/mysqld(mysql_parse(THD*, Parser_state*, bool)+0x3e0) [0x55a417111b80]
mysql     | /usr/sbin/mysqld(dispatch_command(THD*, COM_DATA const*, enum_server_command)+0x2d13) [0x55a417114cc3]

mysql     | /usr/sbin/mysqld(do_command(THD*)+0x180) [0x55a4171157d0]
mysql     | /usr/sbin/mysqld(+0xe113e8) [0x55a4172123e8]
mysql     | /usr/sbin/mysqld(+0x204da2f) [0x55a41844ea2f]
mysql     | /lib/x86_64-linux-gnu/libpthread.so.0(+0x7494) [0x7fe491b38494]
mysql     | /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f) [0x7fe48fe8dacf]
mysql     | 
mysql     | Trying to get some variables.
mysql     | Some pointers may be invalid and cause the dump to abort.
mysql     | Query (7fe42400b4f8): /* ApplicationName=DataGrip 2018.2.4 */ update request set     request_user_position_name = regexp_replace(request_user_position_name, '^(.{1})(.*)', '$1XXXXXX')
mysql     | Connection ID (thread ID): 8
mysql     | Status: NOT_KILLED
mysql     | 
mysql     | The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
mysql     | information that should help you find out what is causing the crash.

これでエラー回避

UPDATE table
SET
  name = CASE WHEN name REGEXP '^(.{1})(.*)'
    THEN REGEXP_REPLACE(name, '^(.{1})(.*)', '$1XX') END;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0