depart_table.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const BaseUtil = require('./baseUtils');
  2. const ledgerTables = ['zh_ledger', 'zh_ledger_extra', 'zh_revise_bills', 'zh_stage_bills', 'zh_stage_bills_final'];
  3. const ledgerDepartKey = ['tender_id', 'tid', 'tender_id', 'tid', 'tid', 'tid'];
  4. const ledgerPrimaryKey = ['uuid', 'uuid', 'uuid', 'id', 'id', 'id'];
  5. const posTables = ['zh_pos', 'zh_pos_extra', 'zh_revise_pos', 'zh_stage_pos', 'zh_stage_pos_final'];
  6. const posDepartKey = ['tid', 'tid', 'tid', 'tid', 'tid', 'tid'];
  7. const posPrimaryKey = ['uuid', 'uuid', 'uuid', 'id', 'id', 'id'];
  8. const orgLedgerDepart = 10, orgPosDepart = 20;
  9. const tableDepart = 100;
  10. const sqlArr = [];
  11. const getDepartSql = function (table, key, primaryKey, orgDepart, newDepart) {
  12. sqlArr.push(`-- ${table}`);
  13. sqlArr.push(`-- ${table} RENAME`);
  14. for (let i = 0; i < orgDepart; i++) {
  15. sqlArr.push(`RENAME TABLE ${table}_${i} TO ${table}_bak_${i};`);
  16. }
  17. sqlArr.push(`-- ${table} RE_DEPART`);
  18. for (let i = 0; i < newDepart; i++) {
  19. const orgDepartIndex = i % orgDepart;
  20. sqlArr.push(`Create Table ${table}_${i} LIKE ${table}_bak_${orgDepartIndex};`);
  21. sqlArr.push(`INSERT INTO ${table}_${i} SELECT * FROM ${table}_bak_${orgDepartIndex} WHERE ${key} % 100 = ${i};`);
  22. }
  23. sqlArr.push('');
  24. };
  25. const getArrDepartSql = function(tableArr, keyArr, primaryKeyArr, orgDepart, newDepart) {
  26. for (let i = 0, iLen = tableArr.length; i < iLen; i++) {
  27. getDepartSql(tableArr[i], keyArr[i], primaryKeyArr[i], orgDepart, newDepart);
  28. }
  29. };
  30. getArrDepartSql(ledgerTables, ledgerDepartKey, ledgerPrimaryKey, orgLedgerDepart, tableDepart);
  31. getArrDepartSql(posTables, posDepartKey, posPrimaryKey, orgPosDepart, tableDepart);
  32. BaseUtil.saveBufferFile(sqlArr.join('\n'), BaseUtil.getFileName('depart_table_qa.sql'));
  33. // Select Sum(amount) FROM (
  34. // Select Count(*) As amount From zh_settle_bills_bak_0
  35. // UNION ALL
  36. // Select Count(*) As amount From zh_settle_bills_bak_1
  37. // UNION ALL
  38. // Select Count(*) As amount From zh_settle_bills_bak_2
  39. // UNION ALL
  40. // Select Count(*) As amount From zh_settle_bills_bak_3
  41. // UNION ALL
  42. // Select Count(*) As amount From zh_settle_bills_bak_4
  43. // UNION ALL
  44. // Select Count(*) As amount From zh_settle_bills_bak_5
  45. // UNION ALL
  46. // Select Count(*) As amount From zh_settle_bills_bak_6
  47. // UNION ALL
  48. // Select Count(*) As amount From zh_settle_bills_bak_7
  49. // UNION ALL
  50. // Select Count(*) As amount From zh_settle_bills_bak_8
  51. // UNION ALL
  52. // Select Count(*) As amount From zh_settle_bills_bak_9
  53. // ) As temp;
  54. // 数据量预估
  55. // qa执行时间(分表100)
  56. // zh_ledger: 320s(876461条)
  57. // zh_ledger_extra: 80s(155730条)
  58. // zh_revise_bills: 230s(386041条)
  59. // zh_stage_bills: 90s(80435条)
  60. // zh_stage_bills_final: 90s(108374条)
  61. // zh_pos: 480s(3122249条)
  62. // zh_pos_extra: 50s(77条)
  63. // zh_revise_pos: 350s(1173963条)
  64. // zh_stage_pos: 110s(380576条)
  65. // zh_stage_pos_final: 130s(658929条)
  66. // uat执行时间(分表100)
  67. // zh_ledger: 100s(600219条)
  68. // zh_ledger_extra: 10s(10386条)
  69. // zh_revise_bills: 20s(51352条)
  70. // zh_stage_bills: 10s(33862条)
  71. // zh_stage_bills_final: 20s(135090条)
  72. // zh_pos: 180s(2088342条)
  73. // zh_pos_extra: 10s(102845条)
  74. // zh_revise_pos: 30s(162054条)
  75. // zh_stage_pos: 30s(148945条)
  76. // zh_stage_pos_final: 130s(658929条)
  77. // uat执行时间(分表100)
  78. // zh_ledger: 280s(2637137条)
  79. // zh_ledger_extra: 20s(33004条)
  80. // zh_revise_bills: 160s(1470789条)
  81. // zh_stage_bills: 100s(2017603条)
  82. // zh_stage_bills_final: 160s(7077632条)
  83. // zh_pos: 600s(2088342条)
  84. // zh_pos_extra: 20s(106698条)
  85. // zh_revise_pos: 300s(4270632条)
  86. // zh_stage_pos: 150s(4794451条)
  87. // zh_stage_pos_final: 800s(23842851条)