17 private $rowSizeEstimator;
33 $this->rowSizeEstimator = $rowSizeEstimator;
42 $rowMemory = $this->rowSizeEstimator->estimateRowSize();
44 $maxHeapTableSize =
$connection->fetchOne(
'SELECT @@max_heap_table_size;');
45 $tmpTableSize =
$connection->fetchOne(
'SELECT @@tmp_table_size;');
46 $bufferPoolSize =
$connection->fetchOne(
'SELECT @@innodb_buffer_pool_size;');
47 $maxMemoryTableSize = min($maxHeapTableSize, $tmpTableSize);
49 $size = (int) ($rowMemory * $batchSize);
52 if ($size > $bufferPoolSize * .2) {
53 $message =
'Memory size allocated for the temporary table is more than 20% of innodb_buffer_pool_size. ' .
54 'Please update innodb_buffer_pool_size or decrease batch size value '.
55 '(which decreases memory usages for the temporary table). ' .
56 'Current batch size: %1; Allocated memory size: %2 bytes; InnoDB buffer pool size: %3 bytes.';
57 $this->logger->warning(
new \
Magento\Framework\
Phrase(
$message, [$batchSize, $size, $bufferPoolSize]));
60 if ($maxMemoryTableSize < $size) {
61 $connection->query(
'SET SESSION tmp_table_size = ' . $size .
';');
62 $connection->query(
'SET SESSION max_heap_table_size = ' . $size .
';');
__construct(\Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface $rowSizeEstimator, \Psr\Log\LoggerInterface $logger)
ensureBatchSize(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $batchSize)