Discussion on several schemes of order number generation

Source: Internet
Author: User

Cut the crap and go straight to the subject.

Scene: The number of new orders per day in the millions, Order table storage table. The order number must be a number.


Scheme One: Business number + year (two digits after year) + month + day + order number. Core logic, create a new order form to maintain the number of new orders per day, generate orders, query from the table to the number of orders, the combination of the other items above the line into the new order number.


Scenario Two: Create a new global order table, hold an ID field, and each time you generate an order number, insert a record in the global order table, using the ID as the order number for the new order.


Both of the above solutions are able to resolve the uniqueness of the order number in the case of a sub-library, but each time an order number is generated, a record must be inserted (updated) in a single table. There are performance bottlenecks under high concurrency.


Programme III: Revised on the basis of programme II. Use the Table_num table as the order number generation table. According to a certain rule, go to one of the tables to generate an order number. For example, the target table is obtained based on the user ID (UID) and the number of tables. Then insert a record in the target table getting the ID to get the id* table number + (user id% table number) Gets the final order number. Order_no = (uid% tale_num) * table_num + (uid% table_num). Somewhat, the operation of a single table is dispersed into multiple tables, which improves the concurrency capability of the system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.