PATH:
usr
/
include
/
mysql
/
server
/
private
/* Copyright (c) 2023, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ #ifndef LEX_CHARSET_COLLATIONS_INCLUDED #define LEX_CHARSET_COLLATIONS_INCLUDED #include "sql_used.h" struct Charset_collation_map_st { public: struct Elem_st { protected: CHARSET_INFO *m_from; // From a character set CHARSET_INFO *m_to; // To a collation static size_t print_lex_string(char *dst, const LEX_CSTRING &str) { memcpy(dst, str.str, str.length); return str.length; } public: /* Size in text format: 'utf8mb4=utf8mb4_unicode_ai_ci' */ static constexpr size_t text_size_max() { return MY_CS_CHARACTER_SET_NAME_SIZE + 1 + MY_CS_COLLATION_NAME_SIZE; } CHARSET_INFO *from() const { return m_from; } CHARSET_INFO *to() const { return m_to; } void set_to(CHARSET_INFO *cl) { m_to= cl; } size_t print(char *dst) const { const char *dst0= dst; dst+= print_lex_string(dst, m_from->cs_name); *dst++= '='; dst+= print_lex_string(dst, m_to->coll_name); return (size_t) (dst - dst0); } int cmp_by_charset_id(const Elem_st &rhs) const { return m_from->number < rhs.m_from->number ? -1 : m_from->number > rhs.m_from->number ? +1 : 0; } }; class Elem: public Elem_st { public: Elem(CHARSET_INFO *from, CHARSET_INFO *to) { m_from= from; m_to= to; } }; protected: Elem_st m_element[8]; // Should be enough for now uint m_count; uint m_version; static int cmp_by_charset_id(const void *a, const void *b) { return static_cast<const Elem_st*>(a)-> cmp_by_charset_id(*static_cast<const Elem_st*>(b)); } void sort() { qsort(m_element, m_count, sizeof(Elem_st), cmp_by_charset_id); } const Elem_st *find_elem_by_charset_id(uint id) const { if (!m_count) return NULL; int first= 0, last= ((int) m_count) - 1; for ( ; first <= last; ) { const int middle= (first + last) / 2; DBUG_ASSERT(middle >= 0); DBUG_ASSERT(middle < (int) m_count); const uint middle_id= m_element[middle].from()->number; if (middle_id == id) return &m_element[middle]; if (middle_id < id) first= middle + 1; else last= middle - 1; } return NULL; } bool insert(const Elem_st &elem) { DBUG_ASSERT(elem.from()->state & MY_CS_PRIMARY); if (m_count >= array_elements(m_element)) return true; m_element[m_count]= elem; m_count++; sort(); return false; } bool insert_or_replace(const Elem_st &elem) { DBUG_ASSERT(elem.from()->state & MY_CS_PRIMARY); const Elem_st *found= find_elem_by_charset_id(elem.from()->number); if (found) { const_cast<Elem_st*>(found)->set_to(elem.to()); return false; } return insert(elem); } public: void init() { m_count= 0; m_version= 0; } uint count() const { return m_count; } uint version() const { return m_version; } void set(const Charset_collation_map_st &rhs, uint version_increment) { uint version= m_version; *this= rhs; m_version= version + version_increment; } const Elem_st & operator[](uint pos) const { DBUG_ASSERT(pos < m_count); return m_element[pos]; } bool insert_or_replace(const class Lex_exact_charset &cs, const class Lex_extended_collation &cl, bool error_on_conflicting_duplicate); bool insert_or_replace(const LEX_CSTRING &cs, const LEX_CSTRING &cl, bool error_on_conflicting_duplicate, myf utf8_flag); CHARSET_INFO *get_collation_for_charset(Sql_used *used, CHARSET_INFO *cs) const { DBUG_ASSERT(cs->state & MY_CS_PRIMARY); const Elem_st *elem= find_elem_by_charset_id(cs->number); used->used|= Sql_used::CHARACTER_SET_COLLATIONS_USED; if (elem) return elem->to(); return cs; } size_t text_format_nbytes_needed() const { return (Elem_st::text_size_max() + 1/* for ',' */) * m_count; } size_t print(char *dst, size_t nbytes_available) const { const char *dst0= dst; const char *end= dst + nbytes_available; for (uint i= 0; i < m_count; i++) { if (Elem_st::text_size_max() + 1/* for ',' */ > (size_t) (end - dst)) break; if (i > 0) *dst++= ','; dst+= m_element[i].print(dst); } return dst - dst0; } static constexpr size_t binary_size_max() { return 1/*count*/ + 4 * array_elements(m_element); } size_t to_binary(char *dst) const { const char *dst0= dst; *dst++= (char) (uchar) m_count; for (uint i= 0; i < m_count; i++) { int2store(dst, (uint16) m_element[i].from()->number); dst+= 2; int2store(dst, (uint16) m_element[i].to()->number); dst+= 2; } return (size_t) (dst - dst0); } size_t from_binary(const char *src, size_t srclen) { const char *src0= src; init(); if (!srclen) return 0; // Empty uint count= (uchar) *src++; if (srclen < 1 + 4 * count) return 0; for (uint i= 0; i < count; i++, src+= 4) { CHARSET_INFO *cs, *cl; if (!(cs= get_charset(uint2korr(src), MYF(0))) || !(cl= get_charset(uint2korr(src + 2), MYF(0)))) { /* Unpacking from binary format happens on the slave side. If for some reasons the slave does not know about a character set or a collation, just skip the pair here. This pair might not even be needed. */ continue; } insert_or_replace(Elem(cs, cl)); } return src - src0; } bool from_text(const LEX_CSTRING &str, myf utf8_flag); }; #endif // LEX_CHARSET_COLLATIONS_INCLUDED
[+]
..
[-] bounded_queue.h
[edit]
[-] myisamchk.h
[edit]
[-] item_windowfunc.h
[edit]
[-] sp_head.h
[edit]
[-] item_vers.h
[edit]
[-] mysqld_suffix.h
[edit]
[-] custom_conf.h
[edit]
[-] sp_cache.h
[edit]
[-] sql_update.h
[edit]
[-] debug_sync.h
[edit]
[-] sql_partition.h
[edit]
[-] config.h
[edit]
[-] scope.h
[edit]
[-] wsrep_utils.h
[edit]
[-] dur_prop.h
[edit]
[-] wsrep_server_state.h
[edit]
[-] sql_reload.h
[edit]
[-] ha_handler_stats.h
[edit]
[-] sql_cache.h
[edit]
[-] rpl_gtid.h
[edit]
[-] rpl_mi.h
[edit]
[-] log_event_data_type.h
[edit]
[-] pfs_statement_provider.h
[edit]
[-] welcome_copyright_notice.h
[edit]
[-] sql_callback.h
[edit]
[-] span.h
[edit]
[-] wsrep_schema.h
[edit]
[-] lex_charset.h
[edit]
[-] gtid_index.h
[edit]
[-] my_crypt.h
[edit]
[-] sql_type_geom.h
[edit]
[-] wsrep_binlog.h
[edit]
[-] sql_union.h
[edit]
[-] log.h
[edit]
[-] wsrep_client_state.h
[edit]
[-] semisync.h
[edit]
[-] my_compare.h
[edit]
[-] sql_type_string.h
[edit]
[-] my_minidump.h
[edit]
[-] table.h
[edit]
[-] sql_debug.h
[edit]
[-] set_var.h
[edit]
[-] wsrep_client_service.h
[edit]
[-] sql_rename.h
[edit]
[-] sql_mode.h
[edit]
[-] sql_array.h
[edit]
[-] sql_prepare.h
[edit]
[-] my_tracker.h
[edit]
[-] heap.h
[edit]
[-] sql_help.h
[edit]
[-] pfs_transaction_provider.h
[edit]
[-] log_cache.h
[edit]
[-] my_bit.h
[edit]
[-] sql_repl.h
[edit]
[-] my_virtual_mem.h
[edit]
[-] my_service_manager.h
[edit]
[-] deprecation.h
[edit]
[-] field_comp.h
[edit]
[-] mysys_err.h
[edit]
[-] t_ctype.h
[edit]
[-] slave.h
[edit]
[-] sql_plugin_compat.h
[edit]
[-] rpl_injector.h
[edit]
[-] sql_audit.h
[edit]
[-] sp.h
[edit]
[-] client_settings.h
[edit]
[-] sql_analyze_stmt.h
[edit]
[-] pfs_stage_provider.h
[edit]
[-] opt_rewrite_date_cmp.h
[edit]
[-] sql_crypt.h
[edit]
[-] wsrep_applier.h
[edit]
[-] wsrep_high_priority_service.h
[edit]
[-] password.h
[edit]
[-] myisam.h
[edit]
[-] json_schema_helper.h
[edit]
[-] my_decimal.h
[edit]
[-] rpl_rli.h
[edit]
[-] table_cache.h
[edit]
[-] sql_signal.h
[edit]
[-] sql_plugin.h
[edit]
[-] json_table.h
[edit]
[+]
data
[-] filesort_utils.h
[edit]
[-] wsrep_var.h
[edit]
[-] pfs_table_provider.h
[edit]
[-] event_data_objects.h
[edit]
[-] partition_info.h
[edit]
[-] sql_class.h
[edit]
[-] cset_narrowing.h
[edit]
[-] charset_collations.h
[edit]
[-] threadpool.h
[edit]
[-] my_time.h
[edit]
[-] sp_instr.h
[edit]
[-] sql_test.h
[edit]
[-] sql_type_fixedbin.h
[edit]
[-] sql_bitmap.h
[edit]
[-] sql_view.h
[edit]
[-] item_geofunc.h
[edit]
[-] rpl_parallel.h
[edit]
[-] transaction.h
[edit]
[-] waiting_threads.h
[edit]
[-] spatial.h
[edit]
[-] sql_parse.h
[edit]
[-] sql_select.h
[edit]
[-] wsrep_sst.h
[edit]
[-] json_schema.h
[edit]
[-] pfs_file_provider.h
[edit]
[-] sql_get_diagnostics.h
[edit]
[-] sql_insert.h
[edit]
[-] my_tree.h
[edit]
[-] item_jsonfunc.h
[edit]
[-] rpl_reporting.h
[edit]
[-] sql_load.h
[edit]
[-] sql_type_timeofday.h
[edit]
[-] sql_alloc.h
[edit]
[-] item_timefunc.h
[edit]
[-] probes_mysql.h
[edit]
[-] handler.h
[edit]
[-] source_revision.h
[edit]
[-] my_apc.h
[edit]
[-] sql_string.h
[edit]
[-] wsrep_trans_observer.h
[edit]
[-] my_base.h
[edit]
[-] wqueue.h
[edit]
[-] pfs_metadata_provider.h
[edit]
[-] contributors.h
[edit]
[-] wsrep_mutex.h
[edit]
[-] wsrep_priv.h
[edit]
[-] log_event.h
[edit]
[-] wsrep_types.h
[edit]
[-] sql_type_fixedbin_storage.h
[edit]
[-] lex_string.h
[edit]
[-] item_xmlfunc.h
[edit]
[-] datadict.h
[edit]
[-] sql_acl.h
[edit]
[-] probes_mysql_dtrace.h
[edit]
[-] sql_partition_admin.h
[edit]
[-] lock.h
[edit]
[-] my_default.h
[edit]
[-] handle_connections_win.h
[edit]
[-] lex.h
[edit]
[-] sql_do.h
[edit]
[-] wsrep_storage_service.h
[edit]
[-] my_json_writer.h
[edit]
[-] wsrep_event_service.h
[edit]
[-] create_tmp_table.h
[edit]
[-] opt_subselect.h
[edit]
[-] sql_cte.h
[edit]
[-] sql_hset.h
[edit]
[-] thread_cache.h
[edit]
[-] filesort.h
[edit]
[-] wsrep_plugin.h
[edit]
[-] wsrep_xid.h
[edit]
[-] parse_file.h
[edit]
[-] ha_sequence.h
[edit]
[-] sql_expression_cache.h
[edit]
[-] sql_type_real.h
[edit]
[-] sql_binlog.h
[edit]
[-] char_buffer.h
[edit]
[-] wsrep_on.h
[edit]
[-] ft_global.h
[edit]
[-] sql_command.h
[edit]
[-] wsrep_server_service.h
[edit]
[-] vers_string.h
[edit]
[+]
providers
[-] select_handler.h
[edit]
[-] threadpool_winsockets.h
[edit]
[-] sql_type.h
[edit]
[-] item_create.h
[edit]
[-] sql_cmd.h
[edit]
[-] protocol.h
[edit]
[-] group_by_handler.h
[edit]
[-] records.h
[edit]
[-] replication.h
[edit]
[-] sql_sequence.h
[edit]
[-] my_md5.h
[edit]
[-] opt_range.h
[edit]
[+]
atomic
[-] strfunc.h
[edit]
[-] my_atomic.h
[edit]
[-] my_rdtsc.h
[edit]
[-] wsrep_mysqld_c.h
[edit]
[-] scheduler.h
[edit]
[-] wsrep_thd.h
[edit]
[-] tztime.h
[edit]
[-] hostname.h
[edit]
[-] lex_symbol.h
[edit]
[-] rpl_tblmap.h
[edit]
[-] ssl_compat.h
[edit]
[-] semisync_master_ack_receiver.h
[edit]
[-] myisampack.h
[edit]
[-] log_slow.h
[edit]
[-] procedure.h
[edit]
[-] mysqld.h
[edit]
[-] my_stacktrace.h
[edit]
[-] mysqld_default_groups.h
[edit]
[-] sql_digest_stream.h
[edit]
[-] partition_element.h
[edit]
[-] sql_locale.h
[edit]
[-] compat56.h
[edit]
[-] gcalc_tools.h
[edit]
[-] tzfile.h
[edit]
[-] semisync_slave.h
[edit]
[-] wsrep_status.h
[edit]
[-] gstream.h
[edit]
[-] sql_type_int.h
[edit]
[-] opt_trace.h
[edit]
[-] discover.h
[edit]
[-] rpl_filter.h
[edit]
[-] thr_lock.h
[edit]
[-] wsrep_condition_variable.h
[edit]
[-] sql_used.h
[edit]
[-] sql_udf.h
[edit]
[-] simple_tokenizer.h
[edit]
[-] my_libwrap.h
[edit]
[-] my_user.h
[edit]
[-] thr_timer.h
[edit]
[-] winservice.h
[edit]
[-] sql_admin.h
[edit]
[-] create_options.h
[edit]
[-] opt_histogram_json.h
[edit]
[-] sql_db.h
[edit]
[-] sql_connect.h
[edit]
[-] my_cpu.h
[edit]
[-] events.h
[edit]
[-] lex_ident.h
[edit]
[-] thr_malloc.h
[edit]
[-] sp_rcontext.h
[edit]
[-] unireg.h
[edit]
[-] lf.h
[edit]
[-] ilist.h
[edit]
[-] sql_limit.h
[edit]
[-] sql_profile.h
[edit]
[-] sql_statistics.h
[edit]
[-] myisammrg.h
[edit]
[-] threadpool_generic.h
[edit]
[-] gcalc_slicescan.h
[edit]
[-] sql_truncate.h
[edit]
[-] probes_mysql_nodtrace.h
[edit]
[-] rijndael.h
[edit]
[-] rpl_utility.h
[edit]
[-] mariadb.h
[edit]
[-] my_atomic_wrapper.h
[edit]
[-] sql_time.h
[edit]
[-] privilege.h
[edit]
[-] my_handler_errors.h
[edit]
[-] my_stack_alloc.h
[edit]
[-] my_uctype.h
[edit]
[-] ha_partition.h
[edit]
[-] pfs_socket_provider.h
[edit]
[-] rowid_filter.h
[edit]
[-] des_key_file.h
[edit]
[-] sql_error.h
[edit]
[-] sql_analyse.h
[edit]
[-] item_subselect.h
[edit]
[-] service_versions.h
[edit]
[-] wsrep.h
[edit]
[-] sql_trigger.h
[edit]
[-] key.h
[edit]
[-] queues.h
[edit]
[-] lex_token.h
[edit]
[-] semisync_master.h
[edit]
[-] proxy_protocol.h
[edit]
[-] sql_show.h
[edit]
[-] event_queue.h
[edit]
[-] derived_handler.h
[edit]
[-] aligned.h
[edit]
[-] sql_const.h
[edit]
[-] my_counter.h
[edit]
[-] item_cmpfunc.h
[edit]
[-] lex_hash.h
[edit]
[-] opt_trace_context.h
[edit]
[-] sql_manager.h
[edit]
[-] sys_vars_shared.h
[edit]
[-] sql_cursor.h
[edit]
[-] init.h
[edit]
[-] aria_backup.h
[edit]
[-] event_parse_data.h
[edit]
[-] pfs_thread_provider.h
[edit]
[-] item_row.h
[edit]
[-] item_func.h
[edit]
[-] mdl.h
[edit]
[-] sql_type_json.h
[edit]
[-] wsrep_allowlist_service.h
[edit]
[-] sql_priv.h
[edit]
[-] innodb_priv.h
[edit]
[-] hash_filo.h
[edit]
[-] optimizer_costs.h
[edit]
[-] wsrep_mysqld.h
[edit]
[-] xa.h
[edit]
[-] socketpair.h
[edit]
[-] sql_plist.h
[edit]
[-] sql_table.h
[edit]
[-] sql_digest.h
[edit]
[-] event_db_repository.h
[edit]
[-] event_scheduler.h
[edit]
[-] repl_failsafe.h
[edit]
[-] mem_root_array.h
[edit]
[-] sql_servers.h
[edit]
[-] sql_window.h
[edit]
[-] hash.h
[edit]
[-] item_sum.h
[edit]
[-] maria.h
[edit]
[-] session_tracker.h
[edit]
[-] embedded_priv.h
[edit]
[-] message.h
[edit]
[-] derror.h
[edit]
[-] my_check_opt.h
[edit]
[-] sql_sort.h
[edit]
[-] pfs_memory_provider.h
[edit]
[-] rpl_record.h
[edit]
[-] grant.h
[edit]
[-] backup.h
[edit]
[-] sql_schema.h
[edit]
[-] item_strfunc.h
[edit]
[-] sql_join_cache.h
[edit]
[-] sql_explain.h
[edit]
[-] debug.h
[edit]
[-] sp_pcontext.h
[edit]
[-] structs.h
[edit]
[-] optimizer_defaults.h
[edit]
[-] sql_i_s.h
[edit]
[-] sql_tvc.h
[edit]
[-] keycaches.h
[edit]
[-] sql_bootstrap.h
[edit]
[-] ddl_log.h
[edit]
[-] violite.h
[edit]
[-] sql_alter.h
[edit]
[-] rpl_constants.h
[edit]
[-] my_rnd.h
[edit]
[-] assume_aligned.h
[edit]
[-] item.h
[edit]
[-] sql_base.h
[edit]
[-] my_nosys.h
[edit]
[-] sql_list.h
[edit]
[-] pfs_idle_provider.h
[edit]
[-] authors.h
[edit]
[-] sql_lex.h
[edit]
[-] sql_basic_types.h
[edit]
[-] uniques.h
[edit]
[-] my_bitmap.h
[edit]
[-] sql_lifo_buffer.h
[edit]
[-] sql_derived.h
[edit]
[-] multi_range_read.h
[edit]
[-] field.h
[edit]
[-] sql_handler.h
[edit]
[-] sql_delete.h
[edit]