自增序列产生器的实现思路_MySQL
bitsCN.com
自增序列产生器的实现思路 l 需求u 实现MySQL自带的字段值自动增长等效的功能;u 同一应用集群中数据库表的自增类型字段值具有全局唯一性;u 支持数据库级别的水平拆分表,同时还需要支持数据库内部的水平拆分表,其ID值都来源于同一条配置记录; l 存储设计序列产生器配置表increment_config结构:列名称 数据类型 是否为空 默认值 是否自增 主键/索引 备注ID INT UNSIGNED N AUTO_INCREMENT PRIMARY KEY(ID) 唯一标示,无意义TABLE_NAME VARCHAR(40) N UNIQUE INDEX 表名称TABLE_TOTAL TINYINT UNSIGNED N 0 标记数据库内分表的数量COLUMN_NAME VARCHAR(40) N 字段名称START_VALUE BIGINT UNSIGNED N 1 开始值OFFSET_VALUE SMALLINT UNSIGNED N 10000 增长的步长FLAG TINYINT N 0 0–正常;1–作废值GMT_MODIFIED TIMESTAMP N 数据库自动更新此值
备注:1>. GMT_MODIFIED不由程序或人为主动去负责更新与填写,而是通过数据库的特性自动填写与更新;2>. 对于数据库内部的水平分表,即TABLE_TOTAL0,则通过TABLE_NAME+TABLE_TOTAL组合区分;l 对存储表的操作 u 初始化的 SQL对于需要用到序列产生器的表,则在此配置表中增加一条记录,例如:INSERT INTO(TABLE_NAME,TABLE_TOTAL,COLUMN_NAME,START_VALUE,OFFSET_VALUE,FLAG)VALUES(‘msg_’,23, ’MSG_ID’,1,10000,0);u 序列生成器操作的 SQL程序每次获得序列区间段,以及更新相关数据值操作的事务的过程SQL,假设msg_系列表对应的记录,在配置表中ID=1。START TRNSACTION;SELECT ID, TABLE_NAME,COLUMN_NAME,START_VALUE,START_VALUE+OFFSET_VALUE AS END_VALUEFROM increment_config WHERE ID=1 FOR UPDATE;UPDATE increment_config SET START_VALUE=START_VALUE+OFFSET_VALUE WHERE ID=1;COMMIT;l 程序实现建议u 为提供序列产生的速度,而提高业务处理的性能。程序需要以拿序列区间的方式实现,而不是每次需要的时候,都要去数据库获得序列号值;u 程序在每次启动的时候,要初始化配置表中所有有效记录的序列区间值;u 当程序拿到的区间值START_VALUE,经过一段时间使用后达到:START_VALUE=END_VALUE,处理步骤如下: 1>. 挂起当前的序列调用请求;2>. 做序列区间值获取的事务;3>. 把新获得区间值的START_VALUE,给予挂起的调用请求;总结:每个区间值的最大值(END_VALUE)始终作为当前期间的弃用值。 作者 snoopy7713 bitsCN.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Driven by the era of automotive electrification, China's domestic automakers are actively involved in the production of electric supercars. Recently, Haopin, a high-end electric brand owned by GAC Aian, launched an electric supercar called SSR. Previously, BYD's Yangwang U9 also received widespread attention. Recently, a video was circulated on the Internet, purportedly showing Yangwang. U9 test video. In the video, a U9 is speeding on the track. Surprisingly, the vehicle's brake discs flash bright orange, making it look like it is competing in the 24 Hours of Le Mans. Particularly striking is the fact that the brake discs on the front wheels are at least twice as bright as those on the rear wheels. However, it is impossible to determine from the video whether the flash of light is caused by the flames produced by the brake discs during braking or whether it is the lighting effect of the vehicle. exhaust

When some Win7 laptop customers use the numeric keyboard, they encounter the reason why they type u but it becomes 4. what happen? In fact, this is because your laptop has the keyboard integrated into the letter keys. You can fix this problem by simply closing the keyboard. The specific steps are as follows: FN+nunlock key conversion can input English letters normally. This method can also be used if the customer encounters pressing I to change to 5. How to solve the problem that the win7 numeric keyboard u becomes 4:1. For better convenience, the laptop does not have a small keyboard area. Therefore, there are keys that define the function of the numeric keypad. You can use the FN+nunlock key to convert. Some must use shift+numlock to enter English or data. 2.Numpad-

How to use PHP to create and manage database tables With the rapid development of the Internet, databases have become an indispensable part of various websites and applications. In PHP, we can use a database management system (DBMS) such as MySQL to create and manage database tables. This article will teach you how to use PHP to implement this function, with corresponding code examples. Connect to the database First, we need to connect to the database in PHP. You can use the mysqli extension or PDO provided by PHP to achieve this function.

The OKX trading platform offers a variety of rates, including transaction fees, withdrawal fees and financing fees. For spot transactions, transaction fees vary according to transaction volume and VIP level, and adopt the "market maker model", that is, the market charges a lower handling fee for each transaction. In addition, OKX also offers a variety of futures contracts, including currency standard contracts, USDT contracts and delivery contracts, and the fee structure of each contract is also different.

The differences between database views and tables are: 1. A table is a physical structure used to store data in a database, while a view is just a query result set based on a table or multiple tables; 2. A table is the physical storage unit of data, and a view only provides Rules for viewing and operating table data; 3. Views provide an advanced security mechanism for the database, and tables have no security mechanism; 4. Views are abstractions of tables; 5. Views can combine multiple tables in queries, and tables can only query a single table; 6. Tables are permanent structures in the database, views are not; 7. Views can create views with the same name, but tables cannot create tables with the same name, etc.

The article introduces that virtual currency is a digital or virtual currency form that relies on cryptography and trades through peer-to-peer networks, and lists common currencies such as Bitcoin. It is usually available on cryptocurrency exchanges such as Coinbase, and all the advantages and disadvantages of each transaction. It emphasizes that the purchase of virtual currency is high, the price fluctuates greatly, and is prone to fraud and hacking. It reminds you to conduct sufficient research before investing and only invest in funds that can bear losses. The information is for reference only and is not investment advice.

When we use the win10 operating system, some friends need to use UF u8 on the computer because of work but don’t know how to operate it. Regarding this problem, the editor thinks that we can download UF u8 online first, and then go through the properties of the computer. Just make the corresponding settings, such as changing the computer name, modifying the registry, etc. Let’s take a look at how the editor did it for the detailed steps~ UFIDA u8win10 installation tutorial step 1: 1. On the “This PC” icon, select “Properties”; 2. Click Change under computer name, domain and workgroup settings Setting button: 3. Click on the "Computer Name" tab and enter the name that needs to be modified in the computer name field (English letters within 8 digits, excluding punctuation and special symbols); 4.

Database views and tables are two different concepts in the database, with different characteristics and uses. A table is an entity that actually stores data in the database, while a view is a virtual table derived from one or more tables, used to specify way to present and manipulate data. Tables have higher data persistence, while views provide more flexible and convenient data access.
