Method and apparatus for processing a character set
Dynamic library injection and hooking technology in MySQL databases allows for character set additions or modifications without source code changes, simplifying the process and enhancing efficiency.
Patent Information
- Application Number
- CN202411467651.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2044-10-21
AI Technical Summary
When the prior art adds or modifys complex character sets to MySQL databases, it is necessary to modify and recompile the source code of the database, resulting in complex processes and inconvenient management.
Dynamic library injection and hook technology are adopted, and dynamic library injection is injected at the start of the database instance, and the hook function is set to overwrite the character set mount function to realize the addition or modification of the character set without modifying or recompiling the database source code.
It realizes dynamically adding or modifying character sets without changing the database source code, simplifying the operation process and improving the flexibility and efficiency of character set management.
Smart Images

Figure CN119396863B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computers, and particularly to a method and apparatus for processing character sets. Background Art
[0002] The character sets of the MySQL database are divided into simple character sets and complex character sets according to the implementation method. Compared with simple character sets, complex character sets have a larger number of encodings, and some use variable-length encoding methods. The encoding conversion rules and sorting rules of the sorting set cannot be implemented with a simple code value mapping table.
[0003] Taking the addition of a new complex character set (assuming the character set name is "MYSET") to the MySQL database as an example, the following steps need to be implemented: (1) In the MySQL source code, add a source code file for "MYSET", implement the code table and the callback function of the transcoding algorithm in this file, encapsulate the MySQL character set interface data structure, and point the code table pointer and callback function pointer contained in this structure to the implemented code table and transcoding algorithm; (2) Introduce the code for registering the new character set in the MySQL source code; (3) Modify the CMake compilation script file and add the "MYSET" information to the relevant variables; (4) Modify the CMake script file and add the "MYSET" information to the relevant variables; (5) Recompile the MySQL source code. The general process of modifying a complex character set is similar to adding a new complex character set, and the addition operation of the code table and the callback function of the transcoding algorithm needs to be changed to a modification process.
[0004] Adding or modifying a complex character set requires modifying the MySQL source code and recompiling. Summary of the Invention
[0005] In the embodiments of the present disclosure, adding or modifying a character set is realized through dynamic library injection and hook technology, so that when adding or modifying a character set, there is no need to modify or recompile the source code of the database.
[0006] Some embodiments of the present disclosure propose a method for processing character sets, including: in response to the startup of a database instance, in the case of adding or modifying a character set, injecting a dynamic library into the database instance, where the dynamic library is provided with a hook function and transcoding information of the added or modified character set, and the hook function overrides the character set mounting function of the database; in response to the start of initialization of the database instance, calling the hook function and using the character set mounting function to mount the character set.
[0007] In some embodiments, invoking the hook function includes: in response to the first invocation of the hook function, creating and populating first charset information for the newly added charset, where the transcoding information of the newly added charset in the dynamic library is populated into the transcoding information in the first charset information; and registering the first charset information into the global charset table of the database.
[0008] In some embodiments, registering the first charset information into the global charset table of the database includes: pointing the pointer corresponding to the number of the global charset table for the newly added charset to the corresponding first charset information of the newly added charset.
[0009] In some embodiments, the transcoding information of the newly added charset includes a code table and a callback function of the transcoding algorithm.
[0010] In some embodiments, invoking the hook function and mounting the charset using the charset mounting function includes: in response to invoking the hook function, according to the charset mounting function, pointing the pointer corresponding to the number of the current second charset in the global charset table of the database to the corresponding second charset information of the number; determining whether the sort set of the pointed second charset information is the modified charset; in response to the determination result that the sort set of the second charset information is the modified charset, replacing the transcoding information in the second charset information with the transcoding information of the modified charset in the dynamic library.
[0011] In some embodiments, for a non-incrementally modified charset, the transcoding information of the modified charset in the dynamic library includes a code table and a callback function of the transcoding algorithm; replacing the transcoding information in the second charset information with the transcoding information of the modified charset in the dynamic library includes: replacing the code table and the callback function of the transcoding algorithm corresponding to the sort set in the second charset information with the code table and the callback function of the transcoding algorithm of the modified charset in the dynamic library.
[0012] In some embodiments, for an incrementally modified charset, the transcoding information of the modified charset in the dynamic library includes a code table; replacing the transcoding information in the second charset information with the transcoding information of the modified charset in the dynamic library includes: replacing the code table corresponding to the sort set in the second charset information with the code table of the modified charset in the dynamic library, where the code table of the modified charset in the dynamic library adds a new code segment relative to the code table corresponding to the sort set in the second charset information.
[0013] In some embodiments, it further includes: in response to the determination result that the sort set of the second charset information is the modified charset, adjusting the charset attribute information corresponding to the sort set in the second charset information, where the charset attribute information includes at least one of the number of bytes of the encoding, the maximum value of the encoding, and the minimum value of the encoding.
[0014] In some embodiments, injecting a dynamic library into a database instance includes: injecting the dynamic library into the database instance according to the dynamic library corresponding to the newly added or modified character set indicated by the preloaded environment variable.
[0015] In some embodiments, it further includes: when there is no need to add or modify the character set, not injecting the dynamic library into the database instance.
[0016] In some embodiments, the character set includes a complex character set.
[0017] Some embodiments of the present disclosure propose an apparatus for processing a character set, including: a memory; and a processor coupled to the memory, the processor being configured to execute a method for processing the character set based on instructions stored in the memory.
[0018] Some embodiments of the present disclosure propose an apparatus for processing a character set, including: a module for executing a method for processing the character set.
[0019] Some embodiments of the present disclosure propose a computer-readable storage medium, on which computer instructions are stored, and when the computer instructions are executed by a processor, the steps of a method for processing a character set are implemented.
[0020] Some embodiments of the present disclosure propose a computer program product, including computer instructions, and when the computer instructions are executed by a processor, the steps of a method for processing a character set are implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The following will briefly introduce the drawings required for use in the embodiments or related technical descriptions. According to the following detailed description with reference to the drawings, the present disclosure can be more clearly understood.
[0022] Obviously, the drawings in the following description are only some embodiments of the present disclosure, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0023] Figure 1 Schematic diagram showing the principle of character set implementation in some embodiments of the present disclosure.
[0024] Figure 2 Schematic diagram showing the method for processing a character set in some embodiments of the present disclosure.
[0025] Figure 3 Schematic diagram showing the calling of a hook function and the mounting of a character set using a character set mounting function in some embodiments of the present disclosure.
[0026] Figure 4 Schematic diagram showing the modification of character set information for incremental modification of a character set in some embodiments of the present disclosure.
[0027] Figure 5 Structural schematic diagram of a device for processing a character set showing some embodiments of the present disclosure.
[0028] Figure 6 Structural schematic diagram of a device for processing a character set showing some embodiments of the present disclosure. Detailed implementation manners
[0029] It should be noted that: Unless otherwise specifically stated, the relative arrangements of components and steps, numerical expressions and values set forth in these embodiments do not limit the scope of the present disclosure.
[0030] Those skilled in the art can understand that terms such as "first", "second", etc. in the embodiments of the present disclosure are only used to distinguish different steps, devices or modules, etc., and do not represent any specific technical meaning nor indicate an inevitable logical order between them.
[0031] It should also be understood that in the embodiments of the present disclosure, "a plurality of" may mean two or more, and "at least one" may mean one, two or more.
[0032] It should also be understood that for any component, data or structure mentioned in the embodiments of the present disclosure, unless specifically limited or otherwise indicated by the context, it can generally be understood as one or more.
[0033] In addition, the term "and / or" in the present disclosure is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " in the present disclosure generally represents an "or" relationship between the associated objects before and after.
[0034] It should also be understood that the present disclosure emphasizes the differences between various embodiments, and the same or similar parts thereof can be referred to each other. For the sake of brevity, they will not be elaborated one by one.
[0035] Meanwhile, it should be understood that for the sake of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.
[0036] The following description of at least one exemplary embodiment is actually only illustrative and in no way limits the present disclosure, its application or use.
[0037] Techniques, methods and devices known to those of ordinary skill in the relevant art may not be discussed in detail, but where appropriate, the techniques, methods and devices should be regarded as part of the specification.
[0038] It should be noted that like reference numerals and letters refer to like items in the following figures, and thus, once an item is defined in one figure, further discussion thereof is not required in subsequent figures.
[0039] In addition, to avoid obscuring the present disclosure with unnecessary details, only the processing steps and / or device structures that are closely related to at least the solution according to the present disclosure are shown in the figures, while other details that are not closely related to the present disclosure are omitted. It should also be noted that like reference numerals and letters in the figures indicate like items, and thus once an item is defined in one figure, further discussion thereof is not required for subsequent figures.
[0040] Figure 1 Schematic diagram showing the principle of character set implementation of some embodiments of the present disclosure. As Figure 1As shown, set the hook function and the transcoding information of the newly added or modified character set in a dynamic library. Among them, a dynamic library is a collection of pre-compiled executable code. Different from a static library that is linked to the program during compilation, it is loaded into memory during program runtime. The hook function overrides the function of the database's character set mounting function by overriding the function. This character set mounting function is used to implement the mounting of various character sets in the database. Various character sets in the database are recorded in the global character set table of the database (set as all_charsets), and each character set corresponds to its specific character set information (set as CHARSET_INFO). The character set information includes, for example, the character set number (set as number), the character set name (set as csname), the sorting set name (set as stname), the character set attribute information, the code table information (such as the pointer to the code table), and the callback information of the transcoding algorithm (such as the pointer to the callback function of the transcoding algorithm), etc. Among them, the character set attribute information includes, for example, the number of bytes of the encoding, the maximum value of the encoding, the minimum value of the encoding, etc. information. One character set number (or one character set name) may correspond to one or more sorting set names. A character set can be uniquely located through "character set number / character set name" + "sorting set name". For example, a certain Chinese character set corresponds to a character set number num001 and a character set name csname001. This Chinese character set can use pinyin sorting or radical sorting. Then the character set information includes the sorting set name stname001 corresponding to pinyin sorting and the sorting set name stname002 corresponding to radical sorting. A pinyin-sorted Chinese character set and a radical-sorted Chinese character set can be uniquely located through "num001 / csname001" + "stname001 / stname002". The transcoding information of the character set includes, for example, the code table and the callback function of the transcoding algorithm, etc., which are used to implement the information for character encoding format conversion. Among them, the transcoding algorithm is used to calculate the position of the original encoding in the code table according to the input original encoding. The code table is used to query the corresponding target encoding according to the code table position. The transcoding algorithm and the code table are used in combination to determine the corresponding target encoding after the original encoding is transcoded. When it is necessary to modify the character set, the new code table and the callback function of the new transcoding algorithm can be set in the dynamic library to replace the old code table and the callback function of the old transcoding algorithm. A database is a collection that stores a large amount of structured and unstructured data. Databases include, for example, but are not limited to relational databases such as MySQL, PostgreSQL, Oracle, SQL Server, etc. and non-relational databases such as MongoDB, Cassandra, Redis, Elasticsearch, etc.
[0041] Figure 2Schematic diagram of a method for processing a character set according to some embodiments of the present disclosure. The method for processing a character set in this embodiment can be executed by a device for processing a character set. As Figure 2 shown, the method for processing a character set in this embodiment includes the following steps.
[0042] In step 210, in response to the startup of a database instance, in the case where a character set needs to be newly added or modified, a dynamic library is injected into the database instance. As described above, the dynamic library is provided with a hook function and transcoding information of the newly added or modified character set, and the hook function overrides the character set mounting function of the database.
[0043] According to whether a character set needs to be newly added or modified, by setting a preloading environment variable, it is determined whether to inject the dynamic library. In the case where a character set needs to be newly added or modified, the preloading environment variable is set to point to the dynamic library corresponding to the newly added or modified character set. When the database instance starts up, according to the dynamic library corresponding to the newly added or modified character set indicated by the preloading environment variable, the dynamic library is injected into the database instance for loading the dynamic library. For example, the preloading environment variable LD_PRELOAD is used, and the address information of a certain dynamic library corresponding to the newly added or modified character set is assigned to the preloading environment variable LD_PRELOAD. In the case where a character set does not need to be newly added or modified, the preloading environment variable is not set or the preloading environment variable is set not to point to the corresponding dynamic library, then when the database instance starts up, the dynamic library is not injected into the database instance. Thus, when releasing a new version of the database character set or restoring the original database character set version, there is no need to modify the source code of the database.
[0044] The newly added or modified character set includes but is not limited to a simple character set and a complex character set. If the transcoding information of the character set is a code table corresponding to the implementation method of the complex character set and a callback function of the transcoding algorithm, the addition or modification of the complex character set can be realized. Similarly, if the transcoding information of the character set is transcoding information such as a mapping table corresponding to the implementation method of the simple character set, the addition or modification of the simple character set can be realized.
[0045] A database instance is a collection of a memory structure and a set of background processes. It is responsible for managing and maintaining the database and providing access to and operations on data. The relationship between a database instance and a database can be one-to-one or one-to-many. For example, in database systems such as Oracle, one instance can manage one or more databases; while in systems such as MySQL, usually one instance corresponds to one database.
[0046] In step 220, in response to the initialization of the database instance starting, the hook function is called, and the character set is mounted using the character set mounting function.
[0047] Among them, the character set mounting function can be used to mount a newly added character set or a modified character set. Mounting of the newly added character set can be achieved when the hook function is called for the first time, while mounting of the modified character set can be achieved when the hook function is called non-first time. The following combines Figure 3 to describe the specific mounting process.
[0048] Figure 3 Fig. shows a schematic diagram of calling the hook function and mounting the character set by using the character set mounting function in some embodiments of the present disclosure.
[0049] In step 310, it is determined whether the hook function is called for the first time. In response to the hook function being called for the first time, step 320 is executed. In response to the hook function not being called for the first time, step 340 is executed.
[0050] In step 320, in response to the hook function being called for the first time, character set information (named the first character set information) is created and filled for the newly added character set. Among them, the transcoding information of the newly added character set in the dynamic library is filled into the transcoding information in the first character set information. For example, the transcoding information of the newly added character set includes a code table and a callback function of the transcoding algorithm. Then step 330 is executed.
[0051] Among them, the character set information created and filled for the newly added character set includes, for example, a character set number (set as number), a character set name (set as csname), a sorting set name (set as stname), character set attribute information (such as the number of bytes of the encoding, the maximum value of the encoding, the minimum value of the encoding, etc.), code table information (such as a pointer to the code table of the newly added character set in the dynamic library), and callback information of the transcoding algorithm (such as a pointer to the callback function of the transcoding algorithm of the newly added character set in the dynamic library) and so on.
[0052] Among them, there may be one or more newly added character sets, and there is also one or more pieces of the first character set information corresponding to each newly added character set. The processing of each piece of the first character set information is the same.
[0053] In step 330, the first character set information and other character set information that originally needs to be registered are registered into the global character set table of the database. Then, step 340 is executed.
[0054] The pointer of the global character set table corresponding to the number of the newly added character set points to the first character set information corresponding to the newly added character set. Thus, the first character set information is registered into the global character set table of the database. The registration method of other character set information can refer to the registration method of the first character set information.
[0055] In step 340, according to the character set mounting function, the pointer corresponding to the number of the global character set table of the database for the current character set (named the second character set) points to the character set information corresponding to the number (named the second character set information).
[0056] For example, the pointer with CHARSET_INFO::number as the subscript position points to CHARSET_INFO, where CHARSET_INFO represents the second character set information and CHARSET_INFO::number represents the number of the second character set.
[0057] In step 350, it is determined whether the sorting set of the pointed second character set information is the modified character set.
[0058] For example, according to CHARSET_INFO::stname (the sorting set of the second character set information), it is determined whether it is the character set that needs to be modified.
[0059] In step 360, in response to the judgment result that the sorting set of the second character set information is the modified character set, the transcoding information of the modified character set in the dynamic library is used to replace the transcoding information in the second character set information. According to the actual situation of the modification, the character set attribute information corresponding to the sorting set in the second character set information is adjusted, and the character set attribute information includes at least one of the number of bytes of the encoding, the maximum value of the encoding, and the minimum value of the encoding.
[0060] Among them, according to the different modification methods, the modified character set includes the incrementally modified character set and the non-incrementally modified character set. As Figure 4 shown, the incrementally modified character set means adding a new code segment on the basis of the original code segment of the character set. In this case, the code table needs to be modified, the callback function of the transcoding algorithm does not need to be modified, and in addition, the maximum value of the encoding also needs to be adaptively modified. For the non-incrementally modified character set, both the code table and the callback function of the transcoding algorithm need to be modified.
[0061] For the non-incrementally modified character set, the transcoding information of the modified character set in the dynamic library includes the code table and the callback function of the transcoding algorithm. Using the transcoding information of the modified character set in the dynamic library to replace the transcoding information in the second character set information includes: using the code table and the callback function of the transcoding algorithm of the modified character set in the dynamic library to replace the code table and the callback function of the transcoding algorithm corresponding to the sorting set in the second character set information. The replacement method is, for example: the code table pointer and the callback function pointer of the transcoding algorithm corresponding to the sorting set in the second character set information respectively point to the code table and the callback function of the transcoding algorithm of the modified character set in the dynamic library.
[0062] For an incrementally modified character set, the transcoding information of the modified character set in the dynamic library includes a code table. Replacing the transcoding information in the second character set information by using the transcoding information of the modified character set in the dynamic library includes: replacing the code table corresponding to the sorting set in the second character set information by using the code table of the modified character set in the dynamic library, where the code table of the modified character set in the dynamic library adds a new code segment relative to the code table corresponding to the sorting set in the second character set information. The replacement method is, for example: the code table pointer corresponding to the sorting set in the second character set information points to the code table of the modified character set in the dynamic library.
[0063] In the embodiments of the present disclosure, by using dynamic library injection and hook technology, new or modified character sets are implemented, so that when adding or modifying character sets, there is no need to modify or recompile the source code of the database. Whether it is an incremental modification of the character set or a non-incremental modification of the character set, there is no need to modify or recompile the source code of the database.
[0064] Figure 5 The structural schematic diagram of a device for processing a character set showing some embodiments of the present disclosure is as follows Figure 5 As shown, the device 500 for processing a character set in this embodiment includes modules 510-520.
[0065] The injection module 510 is configured to, in response to the startup of a database instance, inject a dynamic library into the database instance when a new or modified character set is required. The dynamic library is provided with a hook function and transcoding information of the new or modified character set, and the hook function overrides the character set mounting function of the database. Inject the dynamic library into the database instance according to the dynamic library corresponding to the new or modified character set indicated by the preloaded environment variable.
[0066] The injection module 510 is configured to: when a new or modified character set is not required, not inject the dynamic library into the database instance.
[0067] The mounting module 520 is configured to, in response to the initialization of the database instance starting, call the hook function and use the character set mounting function to mount the character set.
[0068] The mounting module 520 is configured to, in response to the first call of the hook function, create and populate the first character set information for the newly added character set, where the transcoding information of the newly added character set in the dynamic library is populated into the transcoding information in the first character set information; and register the first character set information to the global character set table of the database. The pointer of the global character set table corresponding to the number of the newly added character set points to the first character set information corresponding to the newly added character set.
[0069] The mounting module 520 is configured to, in response to a call to a hook function (the first call to the hook function or a non-first call to the hook function), mount a function according to a character set, and point a pointer to the number corresponding to the current second character set in the global character set table of the database to the second character set information corresponding to the number; determine whether the sorting set of the pointed second character set information is a modified character set; and in response to the determination result that the sorting set of the second character set information is a modified character set, replace the transcoding information in the second character set information with the transcoding information of the modified character set in the dynamic library.
[0070] Among them, for a non-incrementally modified character set, the transcoding information of the modified character set in the dynamic library includes a code table and a callback function of a transcoding algorithm; replacing the transcoding information in the second character set information with the transcoding information of the modified character set in the dynamic library includes: replacing the code table and the callback function of the transcoding algorithm corresponding to the sorting set in the second character set information with the code table and the callback function of the transcoding algorithm of the modified character set in the dynamic library.
[0071] Among them, for an incrementally modified character set, the transcoding information of the modified character set in the dynamic library includes a code table; replacing the transcoding information in the second character set information with the transcoding information of the modified character set in the dynamic library includes: replacing the code table corresponding to the sorting set in the second character set information with the code table of the modified character set in the dynamic library, where the code table of the modified character set in the dynamic library adds a new code segment relative to the code table corresponding to the sorting set in the second character set information.
[0072] The mounting module 520 is configured to, in response to the determination result that the sorting set of the second character set information is a modified character set, adjust the character set attribute information corresponding to the sorting set in the second character set information, and the character set attribute information includes at least one of the number of bytes of encoding, the maximum value of encoding, and the minimum value of encoding.
[0073] Figure 6 The structural schematic diagram of a device for processing character sets showing some embodiments of the present disclosure. As Figure 6 shown, the device 600 for processing character sets in this embodiment includes: a memory 610 and a processor 620 coupled to the memory 610, and the processor 620 is configured to execute the method for processing character sets in each embodiment based on instructions stored in the memory 610.
[0074] The device 600 for processing character sets may further include an input / output interface 630, a network interface 640, a storage interface 650, etc. These interfaces 630, 640, 650 and the memory 610 and the processor 620 may be connected through a bus 660, for example.
[0075] Among them, the memory 610 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory stores, for example, an operating system, application programs, a boot loader, and other programs.
[0076] Among them, the processor 620 may be implemented in the form of a general-purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete hardware components such as discrete gates or transistors.
[0077] Among them, the input / output interface 630 provides connection interfaces for input / output devices such as a display, a mouse, a keyboard, a touch screen, etc. The network interface 640 provides connection interfaces for various networking devices. The storage interface 650 provides connection interfaces for external storage devices such as an SD card, a USB flash drive, etc. The bus 660 may use any bus structure among a variety of bus structures. For example, the bus structure includes but is not limited to an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MCA) bus, and a Peripheral Component Interconnect (PCI) bus.
[0078] Those skilled in the art should understand that the embodiments of the present disclosure may be provided as a method, a system, or a computer program product. Therefore, the present disclosure may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present disclosure may take the form of a computer program product implemented on one or more (non-transitory) computer-readable storage media (including but not limited to a magnetic disk memory, a CD-ROM, an optical memory, a cloud storage, etc.) containing computer program code. A computer program product should be understood as a software product that mainly realizes its solution through a computer program.
[0079] This disclosure is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the disclosure. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and combinations of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to produce a machine, such that the instructions executed by the processor of the computer or other programmable data processing device produce means for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.
[0080] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable memory produce a manufacture including instruction means for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.
[0081] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operational steps are performed on the computer or other programmable device to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more of the flows Figure 1 one or more of the flows and / or blocks Figure 1 or means for implementing the functions specified in one or more of the blocks.
[0082] The above are only the preferred embodiments of the present disclosure and are not intended to limit the present disclosure. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present disclosure shall be included within the protection scope of the present disclosure.
Claims
1. A method for processing character sets, comprising: In response to the startup of a database instance, in the case of needing to add or modify a character set, injecting a dynamic library into the database instance, wherein the dynamic library is provided with a hook function and transcoding information of the added or modified character set, and the hook function overrides the character set mounting function of the database; In response to the database instance starting to initialize, calling the hook function and using the character set mounting function to mount the character set, wherein, calling the hook function includes: In response to the first call of the hook function, creating and populating first character set information for the added character set, wherein the transcoding information of the added character set in the dynamic library is populated into the transcoding information in the first character set information; and Registering the first character set information and other character set information that originally needed to be registered into the global character set table of the database.
2. The method according to claim 1, wherein Registering the first character set information into the global character set table of the database includes: Pointing the pointer corresponding to the number of the added character set in the global character set table to the corresponding first character set information of the added character set.
3. The method according to any one of claims 1-2, wherein, The transcoding information of the added character set includes a code table and a callback function of the transcoding algorithm.
4. A method for processing character sets, comprising: In response to the startup of a database instance, in the case of needing to add or modify a character set, injecting a dynamic library into the database instance, wherein the dynamic library is provided with a hook function and transcoding information of the added or modified character set, and the hook function overrides the character set mounting function of the database; In response to the database instance starting to initialize, calling the hook function and using the character set mounting function to mount the character set, wherein, calling the hook function and using the character set mounting function to mount the character set includes: In response to calling the hook function, according to the character set mounting function, pointing the pointer corresponding to the number of the current second character set in the global character set table of the database to the corresponding second character set information of the number; Judging whether the sort set of the pointed second character set information is the modified character set; In response to the judgment result that the sort set of the second character set information is the modified character set, using the transcoding information of the modified character set in the dynamic library to replace the transcoding information in the second character set information.
5. The method according to claim 4, wherein For a non-incrementally modified character set, the transcoding information of the modified character set in the dynamic library includes a code table and a callback function of the transcoding algorithm; Using the transcoding information of the modified character set in the dynamic library to replace the transcoding information in the second character set information includes: using the code table and the callback function of the transcoding algorithm of the modified character set in the dynamic library to replace the corresponding code table and the callback function of the transcoding algorithm in the sort set of the second character set information.
6. The method according to claim 4, wherein, For an incrementally modified character set, the transcoding information of the modified character set in the dynamic library includes a code table; Using the transcoding information of the modified character set in the dynamic library to replace the transcoding information in the second character set information includes: using the code table of the modified character set in the dynamic library to replace the corresponding code table in the sort set of the second character set information, wherein the code table of the modified character set in the dynamic library adds new code segments relative to the corresponding code table in the sort set of the second character set information.
7. The method according to any one of claims 4-6, further comprising: In response to a determination result that the sorting set of the second character set information is a modified character set, adjust the character set attribute information corresponding to the sorting set in the second character set information, where the character set attribute information includes at least one of the number of encoded bytes, the maximum value of the encoding, and the minimum value of the encoding.
8. The method according to any one of claims 1-2, 4-6, wherein, Injecting a dynamic library into a database instance includes: Injecting the dynamic library into the database instance according to the dynamic library corresponding to the newly added or modified character set indicated by the preloaded environment variable.
9. The method according to any one of claims 1-2, 4-6 further comprises: When there is no need to add or modify the character set, do not inject the dynamic library into the database instance.
10. The method according to any one of claims 1-2, 4-6, wherein, The character set includes a complex character set.
11. An apparatus for processing a character set, comprising: A memory; And a processor coupled to the memory, the processor being configured to execute the method for processing a character set according to any one of claims 1-10 based on instructions stored in the memory.
12. An apparatus for processing a character set, comprising: A module for executing the method for processing a character set according to any one of claims 1-10.
13. A computer-readable storage medium having computer instructions stored thereon, which when executed by a processor implement the steps of the method for processing a character set according to any one of claims 1-10.
14. A computer program product comprising computer instructions, which when executed by a processor implement the steps of the method for processing a character set according to any one of claims 1-10.
Citation Information
Patent Citations
Method and apparatus for performing statistics on file access frequency and time of program
CN108304304A
Apparatus and method for converting character code
KR1020060092545A