Skip to content

Commit

Permalink
add session properties for prefixsort (prestodb#24043)
Browse files Browse the repository at this point in the history
* add native session properties for prefixsort
  • Loading branch information
zation99 authored Nov 15, 2024
1 parent aee1a78 commit e1bddb3
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
29 changes: 29 additions & 0 deletions presto-docs/src/main/sphinx/presto_cpp/properties-session.rst
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,32 @@ bytes / number of destinations for each destination before producing a Serialize

Maximum number of partitions created by a local exchange.
Affects concurrency for pipelines containing LocalPartitionNode.


``native_spill_prefixsort_enabled``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* **Type:** ``boolean``
* **Default value:** ``false``

Enable the prefix sort or fallback to std::sort in spill. The prefix sort is
faster than std::sort but requires the memory to build normalized prefix
keys, which might have potential risk of running out of server memory.

``native_prefixsort_normalized_key_max_bytes``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* **Type:** ``integer``
* **Default value:** ``128``

Maximum number of bytes to use for the normalized key in prefix-sort.
Use ``0`` to disable prefix-sort.

``native_prefixsort_min_rows``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

* **Type:** ``integer``
* **Default value:** ``130``

Minimum number of rows to use prefix-sort.
The default value has been derived using micro-benchmarking.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class NativeWorkerSessionPropertyProvider
public static final String NATIVE_QUERY_TRACE_MAX_BYTES = "native_query_trace_max_bytes";
public static final String NATIVE_QUERY_TRACE_REG_EXP = "native_query_trace_task_reg_exp";
public static final String NATIVE_MAX_LOCAL_EXCHANGE_PARTITION_COUNT = "native_max_local_exchange_partition_count";
public static final String NATIVE_SPILL_PREFIXSORT_ENABLED = "native_spill_prefixsort_enabled";
public static final String NATIVE_PREFIXSORT_NORMALIZED_KEY_MAX_BYTES = "native_prefixsort_normalized_key_max_bytes";
public static final String NATIVE_PREFIXSORT_MIN_ROWS = "native_prefixsort_min_rows";
private final List<PropertyMetadata<?>> sessionProperties;

@Inject
Expand Down Expand Up @@ -239,6 +242,25 @@ public NativeWorkerSessionPropertyProvider(FeaturesConfig featuresConfig)
"Maximum number of partitions created by a local exchange. " +
"Affects concurrency for pipelines containing LocalPartitionNode",
null,
!nativeExecution),
booleanProperty(
NATIVE_SPILL_PREFIXSORT_ENABLED,
"Enable the prefix sort or fallback to std::sort in spill. " +
"The prefix sort is faster than std::sort but requires the memory to build normalized " +
"prefix keys, which might have potential risk of running out of server memory.",
false,
!nativeExecution),
integerProperty(
NATIVE_PREFIXSORT_NORMALIZED_KEY_MAX_BYTES,
"Maximum number of bytes to use for the normalized key in prefix-sort. " +
"Use 0 to disable prefix-sort.",
128,
!nativeExecution),
integerProperty(
NATIVE_PREFIXSORT_MIN_ROWS,
"Minimum number of rows to use prefix-sort. " +
"The default value (130) has been derived using micro-benchmarking.",
130,
!nativeExecution));
}

Expand Down
28 changes: 28 additions & 0 deletions presto-native-execution/presto_cpp/main/SessionProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,34 @@ SessionProperties::SessionProperties() {
false,
QueryConfig::kMaxLocalExchangePartitionCount,
std::to_string(c.maxLocalExchangePartitionCount()));

addSessionProperty(
kSpillPrefixSortEnabled,
"Enable the prefix sort or fallback to std::sort in spill. The prefix sort is "
"faster than std::sort but requires the memory to build normalized prefix "
"keys, which might have potential risk of running out of server memory.",
BOOLEAN(),
false,
QueryConfig::kSpillPrefixSortEnabled,
std::to_string(c.spillPrefixSortEnabled()));

addSessionProperty(
kPrefixSortNormalizedKeyMaxBytes,
"Maximum number of bytes to use for the normalized key in prefix-sort. "
"Use 0 to disable prefix-sort.",
INTEGER(),
false,
QueryConfig::kPrefixSortNormalizedKeyMaxBytes,
std::to_string(c.prefixSortNormalizedKeyMaxBytes()));

addSessionProperty(
kPrefixSortMinRows,
"Minimum number of rows to use prefix-sort. The default value (130) has been "
"derived using micro-benchmarking.",
INTEGER(),
false,
QueryConfig::kPrefixSortMinRows,
std::to_string(c.prefixSortMinRows()));
}

const std::unordered_map<std::string, std::shared_ptr<SessionProperty>>&
Expand Down
17 changes: 17 additions & 0 deletions presto-native-execution/presto_cpp/main/SessionProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,23 @@ class SessionProperties {
static constexpr const char* kMaxLocalExchangePartitionCount =
"native_max_local_exchange_partition_count";

/// Enable the prefix sort or fallback to std::sort in spill. The prefix sort
/// is faster than std::sort but requires the memory to build normalized
/// prefix keys, which might have potential risk of running out of server
/// memory.
static constexpr const char* kSpillPrefixSortEnabled =
"spill_prefixsort_enabled";

/// Maximum number of bytes to use for the normalized key in prefix-sort. Use
/// 0 to disable prefix-sort.
static constexpr const char* kPrefixSortNormalizedKeyMaxBytes =
"native_prefixsort_normalized_key_max_bytes";

/// Minimum number of rows to use prefix-sort. The default value (130) has
/// been derived using micro-benchmarking.
static constexpr const char* kPrefixSortMinRows =
"native_prefixsort_min_rows";

SessionProperties();

const std::unordered_map<std::string, std::shared_ptr<SessionProperty>>&
Expand Down

0 comments on commit e1bddb3

Please sign in to comment.