基于双排序原理的先进先出数据核销高速通用算法
2021-03-24王国忠



摘 要:本文按照软件中台的思想,设计了一个针对先进先出(First-In First-Out, FIFO)[1]数据核销的通用实现框架及其对应的入库数据模型、消费数据模型和匹配核销模型。同时,设计了基于双排序原理的先进先出数据核销高速实现方法。该方法按照匹配规则先对数据进行排序,然后对两个有序队列进行单循环匹配查找,避免了传统先进先出实现中的双循环操作,可以大幅度提高运算性能,大幅度节省CPU开销和存储开销,实现超大数据量的快速匹配,可以支持两个亿级数据库的快速先进先出匹配。
关键词:先进先出;存储过程;双排序;面向对象
中图分类号:TP31 文献标识码:A
Abstract: This paper proposed to design a general implementation framework for FIFO (First-In First-Out) data verification and its corresponding inbound data model, consumption data model and matching verification model based on idea of middle platform. At the same time, a high-speed realization method of FIFO data verification is designed based on the double sorting principle. This method first sorts data according to matching rules, and then performs a single-loop matching search on the two ordered queues, avoiding double-loop operation in traditional FIFO implementation. The proposed method significantly improves computing performance, and greatly saves CPU and storage overheads. As a result, it is capable of processing super large data volume, and can support fast FIFO matching of two databases with large data volume.
Keywords: First-In First-Out (FIFO); storage procedure; double sort; object-oriented
1 引言(Introduction)
先进先出是传统库存商品成本核算的一个通用方法,商品销售先选择最早采购的商品价格作为销售商品的库存成本。目前,国内很多企业对于各类消费数据都需要用先进先出的方法进行核算。随着互联网新零售大幅度崛起,消费数据从传统的商品批发零售扩大到很多场景,例如CRM[2](Customer Relationship Management)的积分核销[3]就是十分典型的一个应用,不同商家的积分产生和使用,需要相互结算。随着全渠道零售的兴起,各个结算主体之间也存在先进先出的结算需求。从软件实现上来看,数据库先进先出核销需要解决模块化和运算高效的技术难点。先进先出算法的缺陷会使系统运行性能变差,甚至导致系统瘫痪。
为了节省服务器的计算时间,需要设计一个通用的高速核销引擎,方便应用程序直接调用,大幅度降低普通程序员对出入数据核销实现的门槛。……
