depart_table.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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条)