| 1812 | |
| 1813 | template <bool isRepartition> |
| 1814 | bool HashBuild::calculateJoinBits( |
| 1815 | uint8_t maxjoinBits, |
| 1816 | uint64_t maxPartitionRowCount) { |
| 1817 | uint32_t numPartitions; |
| 1818 | uint64_t rowsInMem = table_->rows()->numRows(); |
| 1819 | |
| 1820 | uint64_t totalRowCnt{0}, processedRowCnt{0}; |
| 1821 | if constexpr (!isRepartition) { |
| 1822 | operatorCtx_->traverseOpToGetRowCount(totalRowCnt, processedRowCnt); |
| 1823 | spillThreshold_ = rowsInMem; |
| 1824 | memoryUsedForFirstSpill_ = pool()->currentBytes(); |
| 1825 | |
| 1826 | if (totalRowCnt <= 0 || processedRowCnt <= 0) { |
| 1827 | LOG(INFO) << name() << " DO NOTHING!!! totalRowCnt=" << totalRowCnt |
| 1828 | << ", processedRowCnt=" << processedRowCnt; |
| 1829 | return false; |
| 1830 | } |
| 1831 | |
| 1832 | int32_t maxPartitionRowCnt = |
| 1833 | std::min((uint64_t)maxHashTableBucketCount_, processedRowCnt); |
| 1834 | numPartitions = |
| 1835 | (totalRowCnt + maxPartitionRowCnt) / (maxPartitionRowCnt + 1); |
| 1836 | } else { |
| 1837 | if (maxPartitionRowCount > 0 && spillThreshold_.has_value()) { |
| 1838 | totalRowCnt = maxPartitionRowCount; |
| 1839 | processedRowCnt = spillThreshold_.value(); |
| 1840 | |
| 1841 | if (totalRowCnt <= 0 || processedRowCnt <= 0) { |
| 1842 | LOG(INFO) << name() << " DO NOTHING!!! totalRowCnt=" << totalRowCnt |
| 1843 | << ", processedRowCnt=" << processedRowCnt; |
| 1844 | return false; |
| 1845 | } |
| 1846 | |
| 1847 | int32_t maxPartitionRowCnt = |
| 1848 | std::min((uint64_t)maxHashTableBucketCount_, processedRowCnt); |
| 1849 | numPartitions = |
| 1850 | (totalRowCnt + maxPartitionRowCnt) / (maxPartitionRowCnt + 1); |
| 1851 | } else { |
| 1852 | return false; |
| 1853 | } |
| 1854 | } |
| 1855 | |
| 1856 | uint8_t estimatedJoinBits = |
| 1857 | sizeof(unsigned int) * CHAR_BIT - __builtin_clz(numPartitions); |
| 1858 | |
| 1859 | uint32_t estimatedPartitions = 1 << estimatedJoinBits; |
| 1860 | if ((estimatedPartitions < spillConfig_->spillPartitionsAdaptiveThreshold && |
| 1861 | numPartitions >= estimatedPartitions / 4 * 3) || |
| 1862 | estimatedPartitions == numPartitions) { |
| 1863 | ++estimatedJoinBits; |
| 1864 | } |
| 1865 | |
| 1866 | LOG(INFO) << name() << " totalRowCnt = " << totalRowCnt |
| 1867 | << ", processedRowCnt = " << processedRowCnt |
| 1868 | << ", maxHashTableSize = " << maxHashTableBucketCount_ |
| 1869 | << ", rowsInMem = " << rowsInMem |
| 1870 | << ", numPartitions = " << numPartitions |
| 1871 | << ", estimatedJoinBits = " << (int)estimatedJoinBits |
nothing calls this directly
no test coverage detected