I have the following problem, I am currently working on a pricing system with SQL Server database, in which I have to work Dynamic pricing .
For which I have the following table.
-
ID_TARIFA
: Primary Key Auto-increment. -
ID_PRODUCTO
: Identifier of the product sold. -
PRECIO
: Product price. -
FECHA_INICIO
andFECHA_FIN
: Range of dates where the price is available. -
CANTIDAD
: Indicates the quantity of products that can be sold at a certain price. -
ACTIVO
: It tells me if the price is active or not.
I put this information as an example:
The problem is that there are many products and many fees and there is a need to consult this information in real time.
Taking into account this information, a first set of tests was carried out in which:
- A field was created in the table that counted the number of products sold at the indicated price
VENDIDOS
. - A process was created that every time a product was sold it updated the aforementioned field
VENDIDOS
. - Finally, a job was created that was executed every five minutes to update the active prices.
The result of these first tests was that updating the table when selling a product and in turn, after five minutes with the job, ended up blocking the system so that it could not continue to be sold, so it was discarded.
Then in a second set of tests:
- The
VENDIDOS
field was changed to a calculated field that executed a function to obtain products sold. - The
ACTIVO
field was changed to a calculated field that executed a function that based on the parameters returned if the record was active or was not active.
Finally, this second set of tests worked well in a backup environment, however, when it was raised to production, the registration of products sold and the amount of calculations that were made at the time of the consultations ended up collapsing the processor.
The question is, what would be the best way to implement this validation?
I have the theory of eliminating the field ACTIVO
and always make queries in hot, with WHERE
, AND
, and verify the tickets sold at that moment. However, I do not know if it's the best approach.
Edition 01 / 26-10-2016
The size of the tables is as follows, in approximate amounts:
- Sales Table - 120,000,000 (Arox)
- Stock Chart - 6,000,000 (Arox)
- Price Table - 6,000,000 (Approx)
The number of active connections varies between 100 and 2000 in the periods of greatest demand.
The indexes of all the tables are optimized, through analysis tests of the execution plan and SQL Server Profiler.
To show the products they are listed through filters that do not have greater complexity or delay, however it is by consulting the "dynamic prices" (There is always one for each product) where the saturation occurs.