I have always used MS Access and have previously created summary tables(maketable query) using my main data table, ie my main data has all sales information at invoice, I then create a summary table of sales by customer which means I have less rows in that table when viewing by an Intranet page which is far quicker to display.
I have now decided to move over to MYSQL and there is no maketable command, but I can create a table called "customersales" based on a select query. I have 1 million rows in my main table called "sales". Doing it this way, it takes 257 seconds to complete this which to me seems very slow. The result actually returns 47000 records into the new table
Below is my create table statement:-
CREATE DEFINER= root
@ localhost
PROCEDURE 'CREATE_SALESCUSTOMER' () BEGIN
SET SQL_SAFE_UPDATES = 0;
delete from salescustomer;
INSERT
INTO SALESCUSTOMER(SumOfNET, SUMOFGROSS, SumOfQTY, SUMOFSQMQUANTITY,
SUMOFMARGIN, SumOfBUDGETNET,SumOfBUDGETMARGIN,SumOfBUDGETSQM,
VKORG,VKBURORDER,VKGRPORDER,SALESGROUPORDER,SALESOFFICEORDER,
CUSTOMER,NAME1,KUNN2,PARTNERNAME,PERDE,GJAHR,SALESDIRECTOR,
SALESDIRECTORNAME,VKBUR,VKGRP,SALESGROUP,SALESOFFICE,
STRAS,ORT02,ORT01, COUNTY,PSTLZ,TELF1,konda,kondatext
)
SELECT Sum(SALES.NET_SALES) AS SumOfNET,Sum(SALES.NET_SALES) AS SUMOFGROSS,
Sum(SALES.QTY) AS SumOfQTY,
Sum(SALES.SUMOFSQMQUANTITY) AS SUMOFSQMQUANTITY,
Sum(SALES.UKMARGIN) AS SUMOFMARGIN,
Sum(SALES.BUDGETNET) AS SumOfBUDGETNET,
Sum(SALES.BUDGETMARGIN) AS SumOfBUDGETMARGIN,
Sum(SALES.BUDGETSQM) AS SumOfBUDGETSQM,
SALES.VKORG,SALES.VKBURORDER,
SALES.VKGRPORDER,SALES.SALESGROUPORDER,
SALES.SALESOFFICEORDER,SALES.CUSTOMER,SALES.NAME1,SALES.KUNN2,
SALES.PARTNERNAME,SALES.PERDE,SALES.GJAHR,SALES.SALESDIRECTOR,
SALES.SALESDIRECTORNAME,SALES.VKBUR,SALES.VKGRP,SALES.SALESGROUP,
SALES.SALESOFFICE,STRAS,ORT02,ORT01, COUNTY,PSTLZ,TELF1,
konda,kondatext
FROM SALES
GROUP BY konda,kondatext,SALES.VKORG,SALES.VKBURORDER,SALES.VKGRPORDER,
SALES.SALESGROUPORDER,SALES.SALESOFFICEORDER,SALES.CUSTOMER,
SALES.NAME1,SALES.KUNN2,SALES.PARTNERNAME,SALES.PERDE,
SALES.GJAHR;
Can anyone help, am I doing something wrong, is that speed normal. Sorry, bit of a newbie with MYSQL
thanks Kevin
Don't rebuild the Summary table from scratch every time. Instead augment it every day (or week or hour or whatever). Often this is best done with INSERT .. ON DUPLICATE KEY UPDATE .. SELECT ...
. Be sure to have some column so you can "remember where you left off".
This has the side effects of not delivering a full 47K rows each time, and not dropping the table, leaving you without any data briefly.
More discussion: http://mysql.rjweb.org/doc.php/summarytables
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.