Compare commits

...

80 Commits

Author SHA1 Message Date
Maria Khristenko
ea99aa2e12
Merge 9c74e77d52 into b4504f20bf 2024-09-19 21:38:09 +08:00
Raúl Marín
b4504f20bf
Merge pull request #69213 from Algunenano/hide_yo_settings
[RFC] Hide Settings implementation
2024-09-19 12:14:01 +00:00
Mikhail f. Shiryaev
2c29b3d98c
Merge pull request #69750 from ClickHouse/light-env
Make env_helper importable from any module
2024-09-19 10:50:11 +00:00
Nikita Taranov
61524aabb6
Merge pull request #69744 from ClickHouse/fix_pr_protocol
Fix parallel replicas protocol after #68424
2024-09-19 09:21:45 +00:00
Kseniia Sumarokova
39c95f6c73
Merge pull request #62730 from takakawa/bugfix/publication_name_error
[bugfix] MaterializedPostgreSQL Cannot  attach table  when pg dbname  contains "-", need doubleQuoting
2024-09-19 08:54:45 +00:00
Robert Schulze
dfdc25acc9
Merge pull request #69741 from rschu1ze/bump-pg
Bump libpq to v16.4
2024-09-19 08:48:32 +00:00
Nikolay Degterinsky
3efe136635
Merge pull request #69736 from evillique/fix-ttl
Fix METADATA_MISMATCH due to TTL with WHERE
2024-09-19 08:38:55 +00:00
Nikolay Degterinsky
efc0cec707
Merge pull request #69751 from evillique/keepermap-parameters
Save CREATE QUERY with KeeperMap engine with evaluated parameters
2024-09-19 08:38:10 +00:00
Robert Schulze
396abf7636
Merge pull request #69717 from gabrielmcg44/add-array-unscaled
Allow `arrayAUC` without scaling
2024-09-19 08:37:18 +00:00
Kseniia Sumarokova
f8fb4fb120
Merge pull request #69742 from ClickHouse/fix-s3-queue-ttl-sec
s3queue: fix tracked_files_ttl_sec
2024-09-19 08:35:08 +00:00
Raúl Marín
32de45c594 Fix after merging with master 2024-09-19 10:25:22 +02:00
vdimir
1c6165f6ee
Merge pull request #69203 from Avogar/json-dynamic-hash
Fix uniq and GROUP BY for JSON/Dynamic types
2024-09-19 08:24:03 +00:00
Robert Schulze
71dd3d5cf6
Merge pull request #69746 from rschu1ze/sparse-pg
CI: Include PostgreSQL in sparse checkout script
2024-09-19 08:23:41 +00:00
Mikhail f. Shiryaev
cb503ec2ec
Make env_helper importable from any module 2024-09-19 10:22:05 +02:00
Raúl Marín
8efe8066f2 Merge remote-tracking branch 'blessed/master' into hide_yo_settings 2024-09-19 10:09:16 +02:00
Julia Kartseva
9c74e77d52 stress.py 2024-09-19 03:13:56 +00:00
Nikolay Degterinsky
14823f789b Save CREATE QUERY with KeeperMap engine with evaluated parameters 2024-09-19 00:56:59 +00:00
Raúl Marín
9a70e0471c Clang tidy is right 2024-09-18 23:43:49 +02:00
Robert Schulze
bb6db8926e
Some fixups 2024-09-18 20:48:36 +00:00
Nikolay Degterinsky
19353a74db Merge remote-tracking branch 'upstream/master' into fix-ttl 2024-09-18 20:01:49 +00:00
Kruglov Pavel
228ac44a92
Fix asan issue 2024-09-18 21:27:38 +02:00
Robert Schulze
d2de15871c
Include postgres in sparse checkout script 2024-09-18 19:15:13 +00:00
robot-clickhouse
0fdd04254d Automatic style fix 2024-09-18 18:36:34 +00:00
Raúl Marín
a500a7ff50 Link issues and clang tidy 2024-09-18 20:35:52 +02:00
Nikita Taranov
818aac02c6 fix 2024-09-18 19:29:00 +01:00
Gabriel Mendes
7f0b7a9158
add tests to cover all possible flows 2024-09-18 15:17:54 -03:00
Gabriel Mendes
006d14445e
remove stdout files 2024-09-18 14:59:58 -03:00
Kseniia Sumarokova
b5de8e622d
Merge branch 'master' into bugfix/publication_name_error 2024-09-18 19:58:20 +02:00
kssenii
373927d6a5 Fix tracked_files_ttl_sec 2024-09-18 19:25:18 +02:00
Gabriel Mendes
02fcd90a66
address some pr comments 2024-09-18 14:13:22 -03:00
Robert Schulze
e818b65dc0
Bump libpq to v16.4 2024-09-18 17:11:40 +00:00
Nikolay Degterinsky
3315e87e1a Fix METADATA_MISMATCH due to TTL with WHERE 2024-09-18 15:15:52 +00:00
Gabriel Mendes
e0fc95c894
remove trailing spaces 2024-09-18 11:12:30 -03:00
Gabriel Mendes
b940171252
fix tests 2024-09-18 11:04:46 -03:00
Raúl Marín
f3df7bd171 Hide Settings implementation 2024-09-18 15:48:02 +02:00
Gabriel Mendes
e3b207d217
fmt 2024-09-18 09:03:29 -03:00
Gabriel Mendes
4be8a0feba
fmt 2024-09-18 08:58:14 -03:00
Gabriel Mendes
4c72fb0e32
remove unnecessary file 2024-09-18 08:56:13 -03:00
Gabriel Mendes
8f350a7ec9
remove separate function 2024-09-18 08:52:58 -03:00
Gabriel Mendes
2218ebebbf
initial commit, tested function 2024-09-18 05:15:57 -03:00
Julia Kartseva
26f02efa54 Merge remote-tracking branch 'upstream/master' into interactive-metrics-table 2024-09-17 22:07:14 +00:00
Kseniia Sumarokova
d11abd634a
Update max_replication_slots 2024-09-17 16:37:08 +02:00
kssenii
88b22094c8 Update test 2024-09-17 14:11:17 +02:00
kssenii
3cb8160240 Merge remote-tracking branch 'origin' into bugfix/publication_name_error 2024-09-17 14:05:06 +02:00
Julia Kartseva
a8856cd2cc adjust helpers/client.py 2024-09-17 07:50:55 +00:00
Julia Kartseva
cd304cbb53 adjust tests 2024-09-17 06:06:39 +00:00
Julia Kartseva
f72fefe3a3 print a hint 2024-09-17 04:23:21 +00:00
Julia Kartseva
c370e25d19 Merge remote-tracking branch 'upstream/master' into interactive-metrics-table 2024-09-17 01:21:45 +00:00
Julia Kartseva
d837c139b6 fix 2024-09-13 20:01:40 +00:00
Julia Kartseva
a8eac8ed10 Merge remote-tracking branch 'upstream/master' into interactive-metrics-table 2024-09-13 19:44:43 +00:00
Julia Kartseva
75afcb8884 fix toggling 2024-09-13 18:43:16 +00:00
avogar
4ece895b41 Merge branch 'master' of github.com:ClickHouse/ClickHouse into json-dynamic-hash 2024-09-09 10:54:18 +00:00
avogar
f495a4f431 Merge branch 'master' of github.com:ClickHouse/ClickHouse into json-dynamic-hash 2024-09-04 11:21:21 +00:00
avogar
a44b3d0268 Fix sorted typed paths 2024-09-03 17:31:07 +00:00
avogar
f1377b0b4a Fix uniq and GROUP BY for JSON/Dynamic types 2024-09-03 14:10:28 +00:00
Julia Kartseva
3b4f888e45 tidy 2024-08-31 04:09:26 +00:00
Julia Kartseva
49372e58f8 Merge remote-tracking branch 'upstream/master' into interactive-metrics-table 2024-08-29 21:54:34 +00:00
Julia Kartseva
ab874d724d Merge remote-tracking branch 'upstream/master' into interactive-metrics-table 2024-08-22 09:20:49 +00:00
Julia Kartseva
a0944a556b update 2024-08-22 09:16:27 +00:00
Julia Kartseva
1a43929402 remove O_NONBLOCK flag 2024-08-20 08:29:51 +00:00
Julia Kartseva
57bb6f5b90 update progress table 2024-08-20 08:23:31 +00:00
Julia Kartseva
bcfa17bca1 minor 2024-08-20 00:37:54 +00:00
Julia Kartseva
3c5569514c Merge remote-tracking branch 'upstream/master' into interactive-metrics-table 2024-08-19 23:08:32 +00:00
Julia Kartseva
54428becb3 add keystroke interceptor 2024-07-24 04:11:35 +00:00
Julia Kartseva
d00dcda34b use error stream 2024-07-20 02:57:00 +00:00
Julia Kartseva
1ea72d3453 Merge remote-tracking branch 'upstream/master' into interactive-metrics-table 2024-07-20 01:35:30 +00:00
Julia Kartseva
d8f1a0e3bc process stale metrics 2024-07-20 01:14:39 +00:00
Julia Kartseva
c243927c4f address review feedback
- improve color coding for absolute values;
- format style
2024-07-20 01:14:29 +00:00
Julia Kartseva
7fb54c116f improve color coding for bytes-based metrics 2024-07-18 04:54:34 +00:00
Julia Kartseva
6ca11278ce improve color coding for time-based metrics 2024-07-18 03:35:39 +00:00
Julia Kartseva
40e5a60514 render documentation 2024-07-18 00:48:06 +00:00
Julia Kartseva
839601317c make cursor invisible during rendering 2024-07-17 05:35:55 +00:00
Julia Kartseva
132ba9c749 Merge remote-tracking branch 'upstream/master' into interactive-metrics-table 2024-07-17 00:44:54 +00:00
Julia Kartseva
8b567d63b0 Merge remote-tracking branch 'upstream/master' into interactive-metrics-table 2024-07-16 01:08:37 +00:00
Mariia Khristenko
75981aea3d Fix 2024-05-14 08:18:34 +03:00
Mariia Khristenko
692d4fd75d Fix check-style 2024-05-13 18:14:25 +03:00
Mariia Khristenko
6aa2190ebb Fix style 2024-05-13 15:21:17 +03:00
Mariia Khristenko
c87d3502aa Implement ProgressTable 2024-05-13 15:21:17 +03:00
kssenii
5ffa2c9ca1 Add a test 2024-04-25 13:37:24 +02:00
gao chuan
5a6fe87b7c [bugfix]alter postgresql subscription error 2024-04-17 23:43:36 +08:00
573 changed files with 11756 additions and 6186 deletions

2
contrib/postgres vendored

@ -1 +1 @@
Subproject commit cfd77000af28469fcb650485bad65a35e7649e41
Subproject commit 2e51f82e27f4be389cc239d1b8784bbf2f01d33a

View File

@ -38,12 +38,14 @@ set(SRCS
"${POSTGRES_SOURCE_DIR}/src/common/fe_memutils.c"
"${POSTGRES_SOURCE_DIR}/src/common/string.c"
"${POSTGRES_SOURCE_DIR}/src/common/pg_get_line.c"
"${POSTGRES_SOURCE_DIR}/src/common/pg_prng.c"
"${POSTGRES_SOURCE_DIR}/src/common/stringinfo.c"
"${POSTGRES_SOURCE_DIR}/src/common/psprintf.c"
"${POSTGRES_SOURCE_DIR}/src/common/encnames.c"
"${POSTGRES_SOURCE_DIR}/src/common/logging.c"
"${POSTGRES_SOURCE_DIR}/src/port/snprintf.c"
"${POSTGRES_SOURCE_DIR}/src/port/strlcat.c"
"${POSTGRES_SOURCE_DIR}/src/port/strlcpy.c"
"${POSTGRES_SOURCE_DIR}/src/port/strerror.c"
"${POSTGRES_SOURCE_DIR}/src/port/inet_net_ntop.c"
@ -52,6 +54,7 @@ set(SRCS
"${POSTGRES_SOURCE_DIR}/src/port/noblock.c"
"${POSTGRES_SOURCE_DIR}/src/port/pg_strong_random.c"
"${POSTGRES_SOURCE_DIR}/src/port/pgstrcasecmp.c"
"${POSTGRES_SOURCE_DIR}/src/port/pg_bitutils.c"
"${POSTGRES_SOURCE_DIR}/src/port/thread.c"
"${POSTGRES_SOURCE_DIR}/src/port/path.c"
)

View File

@ -0,0 +1,471 @@
/*-------------------------------------------------------------------------
*
* nodetags.h
* Generated node infrastructure code
*
* Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* NOTES
* ******************************
* *** DO NOT EDIT THIS FILE! ***
* ******************************
*
* It has been GENERATED by src/backend/nodes/gen_node_support.pl
*
*-------------------------------------------------------------------------
*/
T_List = 1,
T_Alias = 2,
T_RangeVar = 3,
T_TableFunc = 4,
T_IntoClause = 5,
T_Var = 6,
T_Const = 7,
T_Param = 8,
T_Aggref = 9,
T_GroupingFunc = 10,
T_WindowFunc = 11,
T_SubscriptingRef = 12,
T_FuncExpr = 13,
T_NamedArgExpr = 14,
T_OpExpr = 15,
T_DistinctExpr = 16,
T_NullIfExpr = 17,
T_ScalarArrayOpExpr = 18,
T_BoolExpr = 19,
T_SubLink = 20,
T_SubPlan = 21,
T_AlternativeSubPlan = 22,
T_FieldSelect = 23,
T_FieldStore = 24,
T_RelabelType = 25,
T_CoerceViaIO = 26,
T_ArrayCoerceExpr = 27,
T_ConvertRowtypeExpr = 28,
T_CollateExpr = 29,
T_CaseExpr = 30,
T_CaseWhen = 31,
T_CaseTestExpr = 32,
T_ArrayExpr = 33,
T_RowExpr = 34,
T_RowCompareExpr = 35,
T_CoalesceExpr = 36,
T_MinMaxExpr = 37,
T_SQLValueFunction = 38,
T_XmlExpr = 39,
T_JsonFormat = 40,
T_JsonReturning = 41,
T_JsonValueExpr = 42,
T_JsonConstructorExpr = 43,
T_JsonIsPredicate = 44,
T_NullTest = 45,
T_BooleanTest = 46,
T_CoerceToDomain = 47,
T_CoerceToDomainValue = 48,
T_SetToDefault = 49,
T_CurrentOfExpr = 50,
T_NextValueExpr = 51,
T_InferenceElem = 52,
T_TargetEntry = 53,
T_RangeTblRef = 54,
T_JoinExpr = 55,
T_FromExpr = 56,
T_OnConflictExpr = 57,
T_Query = 58,
T_TypeName = 59,
T_ColumnRef = 60,
T_ParamRef = 61,
T_A_Expr = 62,
T_A_Const = 63,
T_TypeCast = 64,
T_CollateClause = 65,
T_RoleSpec = 66,
T_FuncCall = 67,
T_A_Star = 68,
T_A_Indices = 69,
T_A_Indirection = 70,
T_A_ArrayExpr = 71,
T_ResTarget = 72,
T_MultiAssignRef = 73,
T_SortBy = 74,
T_WindowDef = 75,
T_RangeSubselect = 76,
T_RangeFunction = 77,
T_RangeTableFunc = 78,
T_RangeTableFuncCol = 79,
T_RangeTableSample = 80,
T_ColumnDef = 81,
T_TableLikeClause = 82,
T_IndexElem = 83,
T_DefElem = 84,
T_LockingClause = 85,
T_XmlSerialize = 86,
T_PartitionElem = 87,
T_PartitionSpec = 88,
T_PartitionBoundSpec = 89,
T_PartitionRangeDatum = 90,
T_PartitionCmd = 91,
T_RangeTblEntry = 92,
T_RTEPermissionInfo = 93,
T_RangeTblFunction = 94,
T_TableSampleClause = 95,
T_WithCheckOption = 96,
T_SortGroupClause = 97,
T_GroupingSet = 98,
T_WindowClause = 99,
T_RowMarkClause = 100,
T_WithClause = 101,
T_InferClause = 102,
T_OnConflictClause = 103,
T_CTESearchClause = 104,
T_CTECycleClause = 105,
T_CommonTableExpr = 106,
T_MergeWhenClause = 107,
T_MergeAction = 108,
T_TriggerTransition = 109,
T_JsonOutput = 110,
T_JsonKeyValue = 111,
T_JsonObjectConstructor = 112,
T_JsonArrayConstructor = 113,
T_JsonArrayQueryConstructor = 114,
T_JsonAggConstructor = 115,
T_JsonObjectAgg = 116,
T_JsonArrayAgg = 117,
T_RawStmt = 118,
T_InsertStmt = 119,
T_DeleteStmt = 120,
T_UpdateStmt = 121,
T_MergeStmt = 122,
T_SelectStmt = 123,
T_SetOperationStmt = 124,
T_ReturnStmt = 125,
T_PLAssignStmt = 126,
T_CreateSchemaStmt = 127,
T_AlterTableStmt = 128,
T_ReplicaIdentityStmt = 129,
T_AlterTableCmd = 130,
T_AlterCollationStmt = 131,
T_AlterDomainStmt = 132,
T_GrantStmt = 133,
T_ObjectWithArgs = 134,
T_AccessPriv = 135,
T_GrantRoleStmt = 136,
T_AlterDefaultPrivilegesStmt = 137,
T_CopyStmt = 138,
T_VariableSetStmt = 139,
T_VariableShowStmt = 140,
T_CreateStmt = 141,
T_Constraint = 142,
T_CreateTableSpaceStmt = 143,
T_DropTableSpaceStmt = 144,
T_AlterTableSpaceOptionsStmt = 145,
T_AlterTableMoveAllStmt = 146,
T_CreateExtensionStmt = 147,
T_AlterExtensionStmt = 148,
T_AlterExtensionContentsStmt = 149,
T_CreateFdwStmt = 150,
T_AlterFdwStmt = 151,
T_CreateForeignServerStmt = 152,
T_AlterForeignServerStmt = 153,
T_CreateForeignTableStmt = 154,
T_CreateUserMappingStmt = 155,
T_AlterUserMappingStmt = 156,
T_DropUserMappingStmt = 157,
T_ImportForeignSchemaStmt = 158,
T_CreatePolicyStmt = 159,
T_AlterPolicyStmt = 160,
T_CreateAmStmt = 161,
T_CreateTrigStmt = 162,
T_CreateEventTrigStmt = 163,
T_AlterEventTrigStmt = 164,
T_CreatePLangStmt = 165,
T_CreateRoleStmt = 166,
T_AlterRoleStmt = 167,
T_AlterRoleSetStmt = 168,
T_DropRoleStmt = 169,
T_CreateSeqStmt = 170,
T_AlterSeqStmt = 171,
T_DefineStmt = 172,
T_CreateDomainStmt = 173,
T_CreateOpClassStmt = 174,
T_CreateOpClassItem = 175,
T_CreateOpFamilyStmt = 176,
T_AlterOpFamilyStmt = 177,
T_DropStmt = 178,
T_TruncateStmt = 179,
T_CommentStmt = 180,
T_SecLabelStmt = 181,
T_DeclareCursorStmt = 182,
T_ClosePortalStmt = 183,
T_FetchStmt = 184,
T_IndexStmt = 185,
T_CreateStatsStmt = 186,
T_StatsElem = 187,
T_AlterStatsStmt = 188,
T_CreateFunctionStmt = 189,
T_FunctionParameter = 190,
T_AlterFunctionStmt = 191,
T_DoStmt = 192,
T_InlineCodeBlock = 193,
T_CallStmt = 194,
T_CallContext = 195,
T_RenameStmt = 196,
T_AlterObjectDependsStmt = 197,
T_AlterObjectSchemaStmt = 198,
T_AlterOwnerStmt = 199,
T_AlterOperatorStmt = 200,
T_AlterTypeStmt = 201,
T_RuleStmt = 202,
T_NotifyStmt = 203,
T_ListenStmt = 204,
T_UnlistenStmt = 205,
T_TransactionStmt = 206,
T_CompositeTypeStmt = 207,
T_CreateEnumStmt = 208,
T_CreateRangeStmt = 209,
T_AlterEnumStmt = 210,
T_ViewStmt = 211,
T_LoadStmt = 212,
T_CreatedbStmt = 213,
T_AlterDatabaseStmt = 214,
T_AlterDatabaseRefreshCollStmt = 215,
T_AlterDatabaseSetStmt = 216,
T_DropdbStmt = 217,
T_AlterSystemStmt = 218,
T_ClusterStmt = 219,
T_VacuumStmt = 220,
T_VacuumRelation = 221,
T_ExplainStmt = 222,
T_CreateTableAsStmt = 223,
T_RefreshMatViewStmt = 224,
T_CheckPointStmt = 225,
T_DiscardStmt = 226,
T_LockStmt = 227,
T_ConstraintsSetStmt = 228,
T_ReindexStmt = 229,
T_CreateConversionStmt = 230,
T_CreateCastStmt = 231,
T_CreateTransformStmt = 232,
T_PrepareStmt = 233,
T_ExecuteStmt = 234,
T_DeallocateStmt = 235,
T_DropOwnedStmt = 236,
T_ReassignOwnedStmt = 237,
T_AlterTSDictionaryStmt = 238,
T_AlterTSConfigurationStmt = 239,
T_PublicationTable = 240,
T_PublicationObjSpec = 241,
T_CreatePublicationStmt = 242,
T_AlterPublicationStmt = 243,
T_CreateSubscriptionStmt = 244,
T_AlterSubscriptionStmt = 245,
T_DropSubscriptionStmt = 246,
T_PlannerGlobal = 247,
T_PlannerInfo = 248,
T_RelOptInfo = 249,
T_IndexOptInfo = 250,
T_ForeignKeyOptInfo = 251,
T_StatisticExtInfo = 252,
T_JoinDomain = 253,
T_EquivalenceClass = 254,
T_EquivalenceMember = 255,
T_PathKey = 256,
T_PathTarget = 257,
T_ParamPathInfo = 258,
T_Path = 259,
T_IndexPath = 260,
T_IndexClause = 261,
T_BitmapHeapPath = 262,
T_BitmapAndPath = 263,
T_BitmapOrPath = 264,
T_TidPath = 265,
T_TidRangePath = 266,
T_SubqueryScanPath = 267,
T_ForeignPath = 268,
T_CustomPath = 269,
T_AppendPath = 270,
T_MergeAppendPath = 271,
T_GroupResultPath = 272,
T_MaterialPath = 273,
T_MemoizePath = 274,
T_UniquePath = 275,
T_GatherPath = 276,
T_GatherMergePath = 277,
T_NestPath = 278,
T_MergePath = 279,
T_HashPath = 280,
T_ProjectionPath = 281,
T_ProjectSetPath = 282,
T_SortPath = 283,
T_IncrementalSortPath = 284,
T_GroupPath = 285,
T_UpperUniquePath = 286,
T_AggPath = 287,
T_GroupingSetData = 288,
T_RollupData = 289,
T_GroupingSetsPath = 290,
T_MinMaxAggPath = 291,
T_WindowAggPath = 292,
T_SetOpPath = 293,
T_RecursiveUnionPath = 294,
T_LockRowsPath = 295,
T_ModifyTablePath = 296,
T_LimitPath = 297,
T_RestrictInfo = 298,
T_PlaceHolderVar = 299,
T_SpecialJoinInfo = 300,
T_OuterJoinClauseInfo = 301,
T_AppendRelInfo = 302,
T_RowIdentityVarInfo = 303,
T_PlaceHolderInfo = 304,
T_MinMaxAggInfo = 305,
T_PlannerParamItem = 306,
T_AggInfo = 307,
T_AggTransInfo = 308,
T_PlannedStmt = 309,
T_Result = 310,
T_ProjectSet = 311,
T_ModifyTable = 312,
T_Append = 313,
T_MergeAppend = 314,
T_RecursiveUnion = 315,
T_BitmapAnd = 316,
T_BitmapOr = 317,
T_SeqScan = 318,
T_SampleScan = 319,
T_IndexScan = 320,
T_IndexOnlyScan = 321,
T_BitmapIndexScan = 322,
T_BitmapHeapScan = 323,
T_TidScan = 324,
T_TidRangeScan = 325,
T_SubqueryScan = 326,
T_FunctionScan = 327,
T_ValuesScan = 328,
T_TableFuncScan = 329,
T_CteScan = 330,
T_NamedTuplestoreScan = 331,
T_WorkTableScan = 332,
T_ForeignScan = 333,
T_CustomScan = 334,
T_NestLoop = 335,
T_NestLoopParam = 336,
T_MergeJoin = 337,
T_HashJoin = 338,
T_Material = 339,
T_Memoize = 340,
T_Sort = 341,
T_IncrementalSort = 342,
T_Group = 343,
T_Agg = 344,
T_WindowAgg = 345,
T_Unique = 346,
T_Gather = 347,
T_GatherMerge = 348,
T_Hash = 349,
T_SetOp = 350,
T_LockRows = 351,
T_Limit = 352,
T_PlanRowMark = 353,
T_PartitionPruneInfo = 354,
T_PartitionedRelPruneInfo = 355,
T_PartitionPruneStepOp = 356,
T_PartitionPruneStepCombine = 357,
T_PlanInvalItem = 358,
T_ExprState = 359,
T_IndexInfo = 360,
T_ExprContext = 361,
T_ReturnSetInfo = 362,
T_ProjectionInfo = 363,
T_JunkFilter = 364,
T_OnConflictSetState = 365,
T_MergeActionState = 366,
T_ResultRelInfo = 367,
T_EState = 368,
T_WindowFuncExprState = 369,
T_SetExprState = 370,
T_SubPlanState = 371,
T_DomainConstraintState = 372,
T_ResultState = 373,
T_ProjectSetState = 374,
T_ModifyTableState = 375,
T_AppendState = 376,
T_MergeAppendState = 377,
T_RecursiveUnionState = 378,
T_BitmapAndState = 379,
T_BitmapOrState = 380,
T_ScanState = 381,
T_SeqScanState = 382,
T_SampleScanState = 383,
T_IndexScanState = 384,
T_IndexOnlyScanState = 385,
T_BitmapIndexScanState = 386,
T_BitmapHeapScanState = 387,
T_TidScanState = 388,
T_TidRangeScanState = 389,
T_SubqueryScanState = 390,
T_FunctionScanState = 391,
T_ValuesScanState = 392,
T_TableFuncScanState = 393,
T_CteScanState = 394,
T_NamedTuplestoreScanState = 395,
T_WorkTableScanState = 396,
T_ForeignScanState = 397,
T_CustomScanState = 398,
T_JoinState = 399,
T_NestLoopState = 400,
T_MergeJoinState = 401,
T_HashJoinState = 402,
T_MaterialState = 403,
T_MemoizeState = 404,
T_SortState = 405,
T_IncrementalSortState = 406,
T_GroupState = 407,
T_AggState = 408,
T_WindowAggState = 409,
T_UniqueState = 410,
T_GatherState = 411,
T_GatherMergeState = 412,
T_HashState = 413,
T_SetOpState = 414,
T_LockRowsState = 415,
T_LimitState = 416,
T_IndexAmRoutine = 417,
T_TableAmRoutine = 418,
T_TsmRoutine = 419,
T_EventTriggerData = 420,
T_TriggerData = 421,
T_TupleTableSlot = 422,
T_FdwRoutine = 423,
T_Bitmapset = 424,
T_ExtensibleNode = 425,
T_ErrorSaveContext = 426,
T_IdentifySystemCmd = 427,
T_BaseBackupCmd = 428,
T_CreateReplicationSlotCmd = 429,
T_DropReplicationSlotCmd = 430,
T_StartReplicationCmd = 431,
T_ReadReplicationSlotCmd = 432,
T_TimeLineHistoryCmd = 433,
T_SupportRequestSimplify = 434,
T_SupportRequestSelectivity = 435,
T_SupportRequestCost = 436,
T_SupportRequestRows = 437,
T_SupportRequestIndexCondition = 438,
T_SupportRequestWFuncMonotonic = 439,
T_SupportRequestOptimizeWindowClause = 440,
T_Integer = 441,
T_Float = 442,
T_Boolean = 443,
T_String = 444,
T_BitString = 445,
T_ForeignKeyCacheInfo = 446,
T_IntList = 447,
T_OidList = 448,
T_XidList = 449,
T_AllocSetContext = 450,
T_GenerationContext = 451,
T_SlabContext = 452,
T_TIDBitmap = 453,
T_WindowObjectData = 454,

View File

@ -66,13 +66,6 @@
reference if 'false' */
#define FLOAT8PASSBYVAL false
/* Define to 1 if gettimeofday() takes only 1 argument. */
/* #undef GETTIMEOFDAY_1ARG */
#ifdef GETTIMEOFDAY_1ARG
# define gettimeofday(a,b) gettimeofday(a)
#endif
/* Define to 1 if you have the `append_history' function. */
/* #undef HAVE_APPEND_HISTORY */
@ -113,9 +106,6 @@
don't. */
#define HAVE_DECL_SNPRINTF 1
/* Define to 1 if you have the declaration of `sigwait', and to 0 if you don't. */
#define HAVE_DECL_SIGWAIT 1
/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
don't. */
#if OS_DARWIN
@ -139,21 +129,12 @@
/* Define to 1 if you have the <dld.h> header file. */
/* #undef HAVE_DLD_H */
/* Define to 1 if you have the `dlopen' function. */
#define HAVE_DLOPEN 1
/* Define to 1 if you have the <editline/history.h> header file. */
/* #undef HAVE_EDITLINE_HISTORY_H */
/* Define to 1 if you have the <editline/readline.h> header file. */
#define HAVE_EDITLINE_READLINE_H 1
/* Define to 1 if you have the `fdatasync' function. */
#define HAVE_FDATASYNC 1
/* Define to 1 if you have the `fls' function. */
/* #undef HAVE_FLS */
/* Define to 1 if you have the `fpclass' function. */
/* #undef HAVE_FPCLASS */
@ -169,12 +150,6 @@
/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
#define HAVE_FSEEKO 1
/* Define to 1 if your compiler understands __func__. */
#define HAVE_FUNCNAME__FUNC 1
/* Define to 1 if your compiler understands __FUNCTION__. */
/* #undef HAVE_FUNCNAME__FUNCTION */
/* Define to 1 if you have __atomic_compare_exchange_n(int *, int *, int). */
/* #undef HAVE_GCC__ATOMIC_INT32_CAS */
@ -194,12 +169,6 @@
/* Define to 1 if you have __sync_compare_and_swap(int64 *, int64, int64). */
/* #undef HAVE_GCC__SYNC_INT64_CAS */
/* Define to 1 if you have the `getaddrinfo' function. */
#define HAVE_GETADDRINFO 1
/* Define to 1 if you have the `gethostbyname_r' function. */
#define HAVE_GETHOSTBYNAME_R 1
/* Define to 1 if you have the `getifaddrs' function. */
#define HAVE_GETIFADDRS 1
@ -218,17 +187,11 @@
/* Define to 1 if you have the `getpeerucred' function. */
/* #undef HAVE_GETPEERUCRED */
/* Define to 1 if you have the `getpwuid_r' function. */
#define HAVE_GETPWUID_R 1
/* Define to 1 if you have the <gssapi_ext.h> header file. */
/* #undef HAVE_GSSAPI_EXT_H */
/* Define to 1 if you have the `getrlimit' function. */
#define HAVE_GETRLIMIT 1
/* Define to 1 if you have the `getrusage' function. */
#define HAVE_GETRUSAGE 1
/* Define to 1 if you have the `gettimeofday' function. */
/* #undef HAVE_GETTIMEOFDAY */
/* Define to 1 if you have the <gssapi/gssapi_ext.h> header file. */
/* #undef HAVE_GSSAPI_GSSAPI_EXT_H */
/* Define to 1 if you have the <gssapi/gssapi.h> header file. */
//#define HAVE_GSSAPI_GSSAPI_H 0
@ -275,18 +238,12 @@
/* Define to 1 if you have the global variable 'int timezone'. */
#define HAVE_INT_TIMEZONE 1
/* Define to 1 if you have support for IPv6. */
#define HAVE_IPV6 1
/* Define to 1 if you have isinf(). */
#define HAVE_ISINF 1
/* Define to 1 if you have the <langinfo.h> header file. */
#define HAVE_LANGINFO_H 1
/* Define to 1 if you have the <ldap.h> header file. */
//#define HAVE_LDAP_H 0
/* Define to 1 if you have the `crypto' library (-lcrypto). */
#define HAVE_LIBCRYPTO 1
@ -351,18 +308,9 @@
/* Define to 1 if you have the <memory.h> header file. */
#define HAVE_MEMORY_H 1
/* Define to 1 if the system has the type `MINIDUMP_TYPE'. */
/* #undef HAVE_MINIDUMP_TYPE */
/* Define to 1 if you have the `mkdtemp' function. */
#define HAVE_MKDTEMP 1
/* Define to 1 if you have the <netinet/in.h> header file. */
#define HAVE_NETINET_IN_H 1
/* Define to 1 if you have the <netinet/tcp.h> header file. */
#define HAVE_NETINET_TCP_H 1
/* Define to 1 if you have the <net/if.h> header file. */
#define HAVE_NET_IF_H 1
@ -372,15 +320,6 @@
/* Define to 1 if you have the <pam/pam_appl.h> header file. */
/* #undef HAVE_PAM_PAM_APPL_H */
/* Define to 1 if you have the `poll' function. */
#define HAVE_POLL 1
/* Define to 1 if you have the <poll.h> header file. */
#define HAVE_POLL_H 1
/* Define to 1 if you have a POSIX-conforming sigwait declaration. */
/* #undef HAVE_POSIX_DECL_SIGWAIT */
/* Define to 1 if you have the `posix_fadvise' function. */
#define HAVE_POSIX_FADVISE 1
@ -399,12 +338,6 @@
/* Define to 1 if the assembler supports PPC's LWARX mutex hint bit. */
/* #undef HAVE_PPC_LWARX_MUTEX_HINT */
/* Define to 1 if you have the `pstat' function. */
/* #undef HAVE_PSTAT */
/* Define to 1 if the PS_STRINGS thing exists. */
/* #undef HAVE_PS_STRINGS */
/* Define to 1 if you have the `pthread_is_threaded_np' function. */
/* #undef HAVE_PTHREAD_IS_THREADED_NP */
@ -420,9 +353,6 @@
/* Define to 1 if you have the <readline/readline.h> header file. */
/* #undef HAVE_READLINE_READLINE_H */
/* Define to 1 if you have the `readlink' function. */
#define HAVE_READLINK 1
/* Define to 1 if you have the `rint' function. */
#define HAVE_RINT 1
@ -444,12 +374,6 @@
/* Define to 1 if you have the `setproctitle' function. */
/* #undef HAVE_SETPROCTITLE */
/* Define to 1 if you have the `setsid' function. */
#define HAVE_SETSID 1
/* Define to 1 if you have the `shm_open' function. */
#define HAVE_SHM_OPEN 1
/* Define to 1 if the system has the type `socklen_t'. */
#define HAVE_SOCKLEN_T 1
@ -468,6 +392,9 @@
/* Define to 1 if you have spinlocks. */
#define HAVE_SPINLOCKS 1
/* Define to 1 if you have the `SSL_CTX_set_cert_cb' function. */
#define HAVE_SSL_CTX_SET_CERT_CB 1
/* Define to 1 if you have the `SSL_CTX_set_num_tickets' function. */
/* #define HAVE_SSL_CTX_SET_NUM_TICKETS */
@ -498,55 +425,19 @@
/* Define to 1 if you have the `strlcpy' function. */
/* #undef HAVE_STRLCPY */
/* Define to 1 if you have the `strtoll' function. */
#define HAVE_STRTOLL 1
#if (!OS_DARWIN)
#define HAVE_STRCHRNUL 1
#endif
/* Define to 1 if you have the `strtoq' function. */
/* #undef HAVE_STRTOQ */
/* Define to 1 if you have the `strtoull' function. */
#define HAVE_STRTOULL 1
/* Define to 1 if you have the `strtouq' function. */
/* #undef HAVE_STRTOUQ */
/* Define to 1 if the system has the type `struct addrinfo'. */
#define HAVE_STRUCT_ADDRINFO 1
/* Define to 1 if the system has the type `struct cmsgcred'. */
/* #undef HAVE_STRUCT_CMSGCRED */
/* Define to 1 if the system has the type `struct option'. */
#define HAVE_STRUCT_OPTION 1
/* Define to 1 if `sa_len' is a member of `struct sockaddr'. */
/* #undef HAVE_STRUCT_SOCKADDR_SA_LEN */
/* Define to 1 if the system has the type `struct sockaddr_storage'. */
#define HAVE_STRUCT_SOCKADDR_STORAGE 1
/* Define to 1 if `ss_family' is a member of `struct sockaddr_storage'. */
#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY 1
/* Define to 1 if `ss_len' is a member of `struct sockaddr_storage'. */
/* #undef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */
/* Define to 1 if `__ss_family' is a member of `struct sockaddr_storage'. */
/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */
/* Define to 1 if `__ss_len' is a member of `struct sockaddr_storage'. */
/* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */
/* Define to 1 if `tm_zone' is a member of `struct tm'. */
#define HAVE_STRUCT_TM_TM_ZONE 1
/* Define to 1 if you have the `symlink' function. */
#define HAVE_SYMLINK 1
/* Define to 1 if you have the `sync_file_range' function. */
/* #undef HAVE_SYNC_FILE_RANGE */
@ -556,45 +447,21 @@
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#define HAVE_SYS_IOCTL_H 1
/* Define to 1 if you have the <sys/ipc.h> header file. */
#define HAVE_SYS_IPC_H 1
/* Define to 1 if you have the <sys/personality.h> header file. */
/* #undef HAVE_SYS_PERSONALITY_H */
/* Define to 1 if you have the <sys/poll.h> header file. */
#define HAVE_SYS_POLL_H 1
/* Define to 1 if you have the <sys/pstat.h> header file. */
/* #undef HAVE_SYS_PSTAT_H */
/* Define to 1 if you have the <sys/resource.h> header file. */
#define HAVE_SYS_RESOURCE_H 1
/* Define to 1 if you have the <sys/select.h> header file. */
#define HAVE_SYS_SELECT_H 1
/* Define to 1 if you have the <sys/sem.h> header file. */
#define HAVE_SYS_SEM_H 1
/* Define to 1 if you have the <sys/shm.h> header file. */
#define HAVE_SYS_SHM_H 1
/* Define to 1 if you have the <sys/signalfd.h> header file. */
/* #undef HAVE_SYS_SIGNALFD_H */
/* Define to 1 if you have the <sys/socket.h> header file. */
#define HAVE_SYS_SOCKET_H 1
/* Define to 1 if you have the <sys/sockio.h> header file. */
/* #undef HAVE_SYS_SOCKIO_H */
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/tas.h> header file. */
/* #undef HAVE_SYS_TAS_H */
/* Define to 1 if you have the <sys/time.h> header file. */
#define HAVE_SYS_TIME_H 1
@ -607,7 +474,6 @@
#endif
/* Define to 1 if you have the <sys/un.h> header file. */
#define HAVE_SYS_UN_H 1
#define _GNU_SOURCE 1 /* Needed for glibc struct ucred */
/* Define to 1 if you have the <termios.h> header file. */
@ -644,9 +510,6 @@
/* Define to 1 if you have unix sockets. */
#define HAVE_UNIX_SOCKETS 1
/* Define to 1 if you have the `unsetenv' function. */
#define HAVE_UNSETENV 1
/* Define to 1 if the system has the type `unsigned long long int'. */
#define HAVE_UNSIGNED_LONG_LONG_INT 1
@ -674,6 +537,9 @@
/* Define to 1 if you have the <uuid/uuid.h> header file. */
/* #undef HAVE_UUID_UUID_H */
/* Define to 1 if your compiler knows the visibility("hidden") attribute. */
/* #undef HAVE_VISIBILITY_ATTRIBUTE */
/* Define to 1 if you have the `vsnprintf' function. */
#define HAVE_VSNPRINTF 1
@ -686,12 +552,6 @@
/* Define to 1 if you have the `wcstombs_l' function. */
/* #undef HAVE_WCSTOMBS_L */
/* Define to 1 if you have the <wctype.h> header file. */
#define HAVE_WCTYPE_H 1
/* Define to 1 if you have the <winldap.h> header file. */
/* #undef HAVE_WINLDAP_H */
/* Define to 1 if your compiler understands __builtin_bswap32. */
/* #undef HAVE__BUILTIN_BSWAP32 */

View File

@ -14,5 +14,6 @@ git config submodule."contrib/icu".update '!../sparse-checkout/update-icu.sh'
git config submodule."contrib/boost".update '!../sparse-checkout/update-boost.sh'
git config submodule."contrib/aws-s2n-tls".update '!../sparse-checkout/update-aws-s2n-tls.sh'
git config submodule."contrib/protobuf".update '!../sparse-checkout/update-protobuf.sh'
git config submodule."contrib/postgres".update '!../sparse-checkout/update-postgres.sh'
git config submodule."contrib/libxml2".update '!../sparse-checkout/update-libxml2.sh'
git config submodule."contrib/brotli".update '!../sparse-checkout/update-brotli.sh'

View File

@ -0,0 +1,16 @@
#!/bin/sh
echo "Using sparse checkout for postgres"
FILES_TO_CHECKOUT=$(git rev-parse --git-dir)/info/sparse-checkout
echo '!/*' > $FILES_TO_CHECKOUT
echo '/src/interfaces/libpq/*' >> $FILES_TO_CHECKOUT
echo '!/src/interfaces/libpq/*/*' >> $FILES_TO_CHECKOUT
echo '/src/common/*' >> $FILES_TO_CHECKOUT
echo '!/src/port/*/*' >> $FILES_TO_CHECKOUT
echo '/src/port/*' >> $FILES_TO_CHECKOUT
echo '/src/include/*' >> $FILES_TO_CHECKOUT
git config core.sparsecheckout true
git checkout $1
git read-tree -mu HEAD

View File

@ -2088,13 +2088,14 @@ Calculate AUC (Area Under the Curve, which is a concept in machine learning, see
**Syntax**
``` sql
arrayAUC(arr_scores, arr_labels)
arrayAUC(arr_scores, arr_labels[, scale])
```
**Arguments**
- `arr_scores` — scores prediction model gives.
- `arr_labels` — labels of samples, usually 1 for positive sample and 0 for negative sample.
- `scale` - Optional. Wether to return the normalized area. Default value: true. [Bool]
**Returned value**

View File

@ -19,6 +19,7 @@
#include <Common/Exception.h>
#include <Common/randomSeed.h>
#include <Common/clearPasswordFromCommandLine.h>
#include <Core/Settings.h>
#include <IO/ReadBufferFromFileDescriptor.h>
#include <IO/WriteBufferFromFile.h>
#include <IO/ReadHelpers.h>
@ -36,7 +37,6 @@
#include <Common/StudentTTest.h>
#include <Common/CurrentMetrics.h>
#include <Common/ErrorCodes.h>
#include <Core/BaseSettingsProgramOptions.h>
/** A tool for evaluating ClickHouse performance.
@ -58,8 +58,9 @@ static constexpr std::string_view DEFAULT_CLIENT_NAME = "benchmark";
namespace ErrorCodes
{
extern const int CANNOT_BLOCK_SIGNAL;
extern const int EMPTY_DATA_PASSED;
extern const int BAD_ARGUMENTS;
extern const int CANNOT_BLOCK_SIGNAL;
extern const int EMPTY_DATA_PASSED;
}
class Benchmark : public Poco::Util::Application
@ -637,7 +638,7 @@ int mainEntryClickHouseBenchmark(int argc, char ** argv)
;
Settings settings;
addProgramOptions(settings, desc);
settings.addToProgramOptions(desc);
boost::program_options::variables_map options;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);

View File

@ -56,6 +56,12 @@ using namespace std::literals;
namespace DB
{
namespace Setting
{
extern const SettingsDialect dialect;
extern const SettingsBool use_client_time_zone;
}
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
@ -307,9 +313,9 @@ void Client::initialize(Poco::Util::Application & self)
config().setString("password", env_password);
/// settings and limits could be specified in config file, but passed settings has higher priority
for (const auto & setting : global_context->getSettingsRef().allUnchanged())
for (const auto & setting : global_context->getSettingsRef().getUnchangedNames())
{
const auto & name = setting.getName();
String name{setting};
if (config().has(name))
global_context->setSetting(name, config().getString(name));
}
@ -340,7 +346,9 @@ try
processConfig();
adjustSettings();
initTTYBuffer(toProgressOption(config().getString("progress", "default")));
initTTYBuffer(toProgressOption(config().getString("progress", "default")),
toProgressOption(config().getString("progress-table", "default")));
initKeystrokeInterceptor();
ASTAlterCommand::setFormatAlterCommandsWithParentheses(true);
{
@ -525,7 +533,7 @@ void Client::connect()
}
}
if (!client_context->getSettingsRef().use_client_time_zone)
if (!client_context->getSettingsRef()[Setting::use_client_time_zone])
{
const auto & time_zone = connection->getServerTimezone(connection_parameters.timeouts);
if (!time_zone.empty())
@ -730,7 +738,7 @@ bool Client::processWithFuzzing(const String & full_query)
}
// Kusto is not a subject for fuzzing (yet)
if (client_context->getSettingsRef().dialect == DB::Dialect::kusto)
if (client_context->getSettingsRef()[Setting::dialect] == DB::Dialect::kusto)
{
return true;
}
@ -1073,17 +1081,7 @@ void Client::processOptions(const OptionsDescription & options_description,
/// Copy settings-related program options to config.
/// TODO: Is this code necessary?
for (const auto & setting : global_context->getSettingsRef().all())
{
const auto & name = setting.getName();
if (options.count(name))
{
if (allow_repeated_settings)
config().setString(name, options[name].as<Strings>().back());
else
config().setString(name, options[name].as<String>());
}
}
global_context->getSettingsRef().addToClientOptions(config(), options, allow_repeated_settings);
if (options.count("config-file") && options.count("config"))
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Two or more configuration files referenced in arguments");

View File

@ -3,11 +3,12 @@
#include <string_view>
#include <boost/program_options.hpp>
#include <IO/copyData.h>
#include <Core/Settings.h>
#include <IO/ReadBufferFromFileDescriptor.h>
#include <IO/ReadHelpers.h>
#include <IO/WriteBufferFromFileDescriptor.h>
#include <IO/WriteBufferFromOStream.h>
#include <IO/copyData.h>
#include <Interpreters/registerInterpreters.h>
#include <Parsers/ASTInsertQuery.h>
#include <Parsers/ParserQuery.h>
@ -17,7 +18,6 @@
#include <Common/ErrorCodes.h>
#include <Common/StringUtils.h>
#include <Common/TerminalSize.h>
#include <Core/BaseSettingsProgramOptions.h>
#include <Interpreters/Context.h>
#include <Functions/FunctionFactory.h>
@ -35,6 +35,15 @@
#include <Formats/registerFormats.h>
#include <Processors/Transforms/getSourceFromASTInsertQuery.h>
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 max_parser_backtracks;
extern const SettingsUInt64 max_parser_depth;
extern const SettingsUInt64 max_query_size;
}
}
namespace DB::ErrorCodes
{
@ -99,12 +108,8 @@ int mainEntryClickHouseFormat(int argc, char ** argv)
;
Settings cmd_settings;
for (const auto & field : cmd_settings.all())
{
std::string_view name = field.getName();
if (name == "max_parser_depth" || name == "max_query_size")
addProgramOption(cmd_settings, desc, name, field);
}
cmd_settings.addToProgramOptions("max_parser_depth", desc);
cmd_settings.addToProgramOptions("max_query_size", desc);
boost::program_options::variables_map options;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
@ -240,7 +245,14 @@ int mainEntryClickHouseFormat(int argc, char ** argv)
size_t approx_query_length = multiple ? find_first_symbols<';'>(pos, end) - pos : end - pos;
ASTPtr res = parseQueryAndMovePosition(
parser, pos, end, "query", multiple, cmd_settings.max_query_size, cmd_settings.max_parser_depth, cmd_settings.max_parser_backtracks);
parser,
pos,
end,
"query",
multiple,
cmd_settings[Setting::max_query_size],
cmd_settings[Setting::max_parser_depth],
cmd_settings[Setting::max_parser_backtracks]);
std::unique_ptr<ReadBuffer> insert_query_payload;
/// If the query is INSERT ... VALUES, then we will try to parse the data.

View File

@ -71,6 +71,11 @@ namespace CurrentMetrics
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_introspection_functions;
extern const SettingsLocalFSReadMethod storage_file_read_method;
}
namespace ErrorCodes
{
@ -83,8 +88,8 @@ void applySettingsOverridesForLocal(ContextMutablePtr context)
{
Settings settings = context->getSettingsCopy();
settings.allow_introspection_functions = true;
settings.storage_file_read_method = LocalFSReadMethod::mmap;
settings[Setting::allow_introspection_functions] = true;
settings[Setting::storage_file_read_method] = LocalFSReadMethod::mmap;
context->setSettings(settings);
}
@ -513,7 +518,9 @@ try
SCOPE_EXIT({ cleanup(); });
initTTYBuffer(toProgressOption(getClientConfiguration().getString("progress", "default")));
initTTYBuffer(toProgressOption(getClientConfiguration().getString("progress", "default")),
toProgressOption(config().getString("progress-table", "default")));
initKeystrokeInterceptor();
ASTAlterCommand::setFormatAlterCommandsWithParentheses(true);
/// try to load user defined executable functions, throw on error and die

View File

@ -4,7 +4,6 @@
#include <Client/LocalConnection.h>
#include <Core/ServerSettings.h>
#include <Core/Settings.h>
#include <Interpreters/Context.h>
#include <Loggers/Loggers.h>
#include <Common/InterruptListener.h>

View File

@ -2,6 +2,7 @@
#if USE_ODBC
#include <Core/NamesAndTypes.h>
#include <Core/Settings.h>
#include <DataTypes/DataTypeFactory.h>
#include <DataTypes/DataTypeNullable.h>
@ -27,6 +28,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 odbc_bridge_connection_pool_size;
}
namespace ErrorCodes
{
@ -129,8 +134,7 @@ void ODBCColumnsInfoHandler::handleRequest(HTTPServerRequest & request, HTTPServ
const bool external_table_functions_use_nulls = Poco::NumberParser::parseBool(params.get("external_table_functions_use_nulls", "false"));
auto connection_holder = ODBCPooledConnectionFactory::instance().get(
validateODBCConnectionString(connection_string),
getContext()->getSettingsRef().odbc_bridge_connection_pool_size);
validateODBCConnectionString(connection_string), getContext()->getSettingsRef()[Setting::odbc_bridge_connection_pool_size]);
/// In XDBC tables it is allowed to pass either database_name or schema_name in table definion, but not both of them.
/// They both are passed as 'schema' parameter in request URL, so it is not clear whether it is database_name or schema_name passed.

View File

@ -19,6 +19,11 @@
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 odbc_bridge_connection_pool_size;
}
void IdentifierQuoteHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response, const ProfileEvents::Event & /*write_event*/)
{
HTMLForm params(getContext()->getSettingsRef(), request, request.getStream());
@ -68,7 +73,7 @@ void IdentifierQuoteHandler::handleRequest(HTTPServerRequest & request, HTTPServ
nanodbc::ConnectionHolderPtr connection;
if (use_connection_pooling)
connection = ODBCPooledConnectionFactory::instance().get(
validateODBCConnectionString(connection_string), getContext()->getSettingsRef().odbc_bridge_connection_pool_size);
validateODBCConnectionString(connection_string), getContext()->getSettingsRef()[Setting::odbc_bridge_connection_pool_size]);
else
connection = std::make_shared<nanodbc::ConnectionHolder>(validateODBCConnectionString(connection_string));

View File

@ -1,27 +1,28 @@
#include "MainHandler.h"
#include "validateODBCConnectionString.h"
#include "ODBCSource.h"
#include "ODBCSink.h"
#include "getIdentifierQuote.h"
#include <Core/Settings.h>
#include <DataTypes/DataTypeFactory.h>
#include <Formats/FormatFactory.h>
#include <Server/HTTP/WriteBufferFromHTTPServerResponse.h>
#include <IO/WriteHelpers.h>
#include <IO/ReadHelpers.h>
#include <Core/Settings.h>
#include <IO/Operators.h>
#include <IO/ReadBufferFromIStream.h>
#include <Poco/Net/HTTPServerRequest.h>
#include <Poco/Net/HTTPServerResponse.h>
#include <Poco/Net/HTMLForm.h>
#include <Poco/ThreadPool.h>
#include <QueryPipeline/QueryPipeline.h>
#include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h>
#include <Processors/Executors/CompletedPipelineExecutor.h>
#include <Processors/Formats/IInputFormat.h>
#include <QueryPipeline/QueryPipeline.h>
#include <Server/HTTP/HTMLForm.h>
#include <Server/HTTP/WriteBufferFromHTTPServerResponse.h>
#include <Poco/Net/HTMLForm.h>
#include <Poco/Net/HTTPServerRequest.h>
#include <Poco/Net/HTTPServerResponse.h>
#include <Poco/ThreadPool.h>
#include <Common/BridgeProtocolVersion.h>
#include <Common/logger_useful.h>
#include <Server/HTTP/HTMLForm.h>
#include "ODBCSink.h"
#include "ODBCSource.h"
#include "config.h"
#include "getIdentifierQuote.h"
#include "validateODBCConnectionString.h"
#include <mutex>
#include <memory>
@ -29,6 +30,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 odbc_bridge_connection_pool_size;
}
namespace
{
@ -139,7 +144,7 @@ void ODBCHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse
nanodbc::ConnectionHolderPtr connection_handler;
if (use_connection_pooling)
connection_handler = ODBCPooledConnectionFactory::instance().get(
validateODBCConnectionString(connection_string), getContext()->getSettingsRef().odbc_bridge_connection_pool_size);
validateODBCConnectionString(connection_string), getContext()->getSettingsRef()[Setting::odbc_bridge_connection_pool_size]);
else
connection_handler = std::make_shared<nanodbc::ConnectionHolder>(validateODBCConnectionString(connection_string));

View File

@ -20,6 +20,11 @@
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 odbc_bridge_connection_pool_size;
}
namespace
{
bool isSchemaAllowed(nanodbc::ConnectionHolderPtr connection_holder)
@ -82,7 +87,7 @@ void SchemaAllowedHandler::handleRequest(HTTPServerRequest & request, HTTPServer
if (use_connection_pooling)
connection = ODBCPooledConnectionFactory::instance().get(
validateODBCConnectionString(connection_string), getContext()->getSettingsRef().odbc_bridge_connection_pool_size);
validateODBCConnectionString(connection_string), getContext()->getSettingsRef()[Setting::odbc_bridge_connection_pool_size]);
else
connection = std::make_shared<nanodbc::ConnectionHolder>(validateODBCConnectionString(connection_string));

View File

@ -148,6 +148,18 @@
/// A minimal file used when the server is run without installation
INCBIN(resource_embedded_xml, SOURCE_DIR "/programs/server/embedded.xml");
namespace DB
{
namespace Setting
{
extern const SettingsSeconds http_receive_timeout;
extern const SettingsSeconds http_send_timeout;
extern const SettingsSeconds receive_timeout;
extern const SettingsSeconds send_timeout;
}
}
namespace CurrentMetrics
{
extern const Metric Revision;
@ -1831,10 +1843,13 @@ try
"Keeper (tcp): " + address.toString(),
std::make_unique<TCPServer>(
new KeeperTCPHandlerFactory(
config_getter, global_context->getKeeperDispatcher(),
global_context->getSettingsRef().receive_timeout.totalSeconds(),
global_context->getSettingsRef().send_timeout.totalSeconds(),
false), server_pool, socket));
config_getter,
global_context->getKeeperDispatcher(),
global_context->getSettingsRef()[Setting::receive_timeout].totalSeconds(),
global_context->getSettingsRef()[Setting::send_timeout].totalSeconds(),
false),
server_pool,
socket));
});
const char * secure_port_name = "keeper_server.tcp_port_secure";
@ -1854,9 +1869,13 @@ try
"Keeper with secure protocol (tcp_secure): " + address.toString(),
std::make_unique<TCPServer>(
new KeeperTCPHandlerFactory(
config_getter, global_context->getKeeperDispatcher(),
global_context->getSettingsRef().receive_timeout.totalSeconds(),
global_context->getSettingsRef().send_timeout.totalSeconds(), true), server_pool, socket));
config_getter,
global_context->getKeeperDispatcher(),
global_context->getSettingsRef()[Setting::receive_timeout].totalSeconds(),
global_context->getSettingsRef()[Setting::send_timeout].totalSeconds(),
true),
server_pool,
socket));
#else
UNUSED(port);
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "SSL support for TCP protocol is disabled because Poco library was built without NetSSL support.");
@ -2430,7 +2449,7 @@ void Server::createServers(
const Settings & settings = global_context->getSettingsRef();
Poco::Net::HTTPServerParams::Ptr http_params = new Poco::Net::HTTPServerParams;
http_params->setTimeout(settings.http_receive_timeout);
http_params->setTimeout(settings[Setting::http_receive_timeout]);
http_params->setKeepAliveTimeout(global_context->getServerSettings().keep_alive_timeout);
http_params->setMaxKeepAliveRequests(static_cast<int>(global_context->getServerSettings().max_keep_alive_requests));
@ -2469,8 +2488,8 @@ void Server::createServers(
{
Poco::Net::ServerSocket socket;
auto address = socketBindListen(config, socket, host, port, is_secure);
socket.setReceiveTimeout(settings.receive_timeout);
socket.setSendTimeout(settings.send_timeout);
socket.setReceiveTimeout(settings[Setting::receive_timeout]);
socket.setSendTimeout(settings[Setting::send_timeout]);
return ProtocolServerAdapter(
host,
@ -2497,8 +2516,8 @@ void Server::createServers(
{
Poco::Net::ServerSocket socket;
auto address = socketBindListen(config, socket, listen_host, port);
socket.setReceiveTimeout(settings.http_receive_timeout);
socket.setSendTimeout(settings.http_send_timeout);
socket.setReceiveTimeout(settings[Setting::http_receive_timeout]);
socket.setSendTimeout(settings[Setting::http_send_timeout]);
return ProtocolServerAdapter(
listen_host,
@ -2518,8 +2537,8 @@ void Server::createServers(
#if USE_SSL
Poco::Net::SecureServerSocket socket;
auto address = socketBindListen(config, socket, listen_host, port, /* secure = */ true);
socket.setReceiveTimeout(settings.http_receive_timeout);
socket.setSendTimeout(settings.http_send_timeout);
socket.setReceiveTimeout(settings[Setting::http_receive_timeout]);
socket.setSendTimeout(settings[Setting::http_send_timeout]);
return ProtocolServerAdapter(
listen_host,
port_name,
@ -2541,8 +2560,8 @@ void Server::createServers(
{
Poco::Net::ServerSocket socket;
auto address = socketBindListen(config, socket, listen_host, port);
socket.setReceiveTimeout(settings.receive_timeout);
socket.setSendTimeout(settings.send_timeout);
socket.setReceiveTimeout(settings[Setting::receive_timeout]);
socket.setSendTimeout(settings[Setting::send_timeout]);
return ProtocolServerAdapter(
listen_host,
port_name,
@ -2563,8 +2582,8 @@ void Server::createServers(
{
Poco::Net::ServerSocket socket;
auto address = socketBindListen(config, socket, listen_host, port);
socket.setReceiveTimeout(settings.receive_timeout);
socket.setSendTimeout(settings.send_timeout);
socket.setReceiveTimeout(settings[Setting::receive_timeout]);
socket.setSendTimeout(settings[Setting::send_timeout]);
return ProtocolServerAdapter(
listen_host,
port_name,
@ -2586,8 +2605,8 @@ void Server::createServers(
#if USE_SSL
Poco::Net::SecureServerSocket socket;
auto address = socketBindListen(config, socket, listen_host, port, /* secure = */ true);
socket.setReceiveTimeout(settings.receive_timeout);
socket.setSendTimeout(settings.send_timeout);
socket.setReceiveTimeout(settings[Setting::receive_timeout]);
socket.setSendTimeout(settings[Setting::send_timeout]);
return ProtocolServerAdapter(
listen_host,
port_name,
@ -2612,7 +2631,7 @@ void Server::createServers(
Poco::Net::ServerSocket socket;
auto address = socketBindListen(config, socket, listen_host, port, /* secure = */ true);
socket.setReceiveTimeout(Poco::Timespan());
socket.setSendTimeout(settings.send_timeout);
socket.setSendTimeout(settings[Setting::send_timeout]);
return ProtocolServerAdapter(
listen_host,
port_name,
@ -2629,7 +2648,7 @@ void Server::createServers(
Poco::Net::ServerSocket socket;
auto address = socketBindListen(config, socket, listen_host, port, /* secure = */ true);
socket.setReceiveTimeout(Poco::Timespan());
socket.setSendTimeout(settings.send_timeout);
socket.setSendTimeout(settings[Setting::send_timeout]);
return ProtocolServerAdapter(
listen_host,
port_name,
@ -2661,8 +2680,8 @@ void Server::createServers(
{
Poco::Net::ServerSocket socket;
auto address = socketBindListen(config, socket, listen_host, port);
socket.setReceiveTimeout(settings.http_receive_timeout);
socket.setSendTimeout(settings.http_send_timeout);
socket.setReceiveTimeout(settings[Setting::http_receive_timeout]);
socket.setSendTimeout(settings[Setting::http_send_timeout]);
return ProtocolServerAdapter(
listen_host,
port_name,
@ -2687,7 +2706,7 @@ void Server::createInterserverServers(
const Settings & settings = global_context->getSettingsRef();
Poco::Net::HTTPServerParams::Ptr http_params = new Poco::Net::HTTPServerParams;
http_params->setTimeout(settings.http_receive_timeout);
http_params->setTimeout(settings[Setting::http_receive_timeout]);
http_params->setKeepAliveTimeout(global_context->getServerSettings().keep_alive_timeout);
/// Now iterate over interserver_listen_hosts
@ -2703,8 +2722,8 @@ void Server::createInterserverServers(
{
Poco::Net::ServerSocket socket;
auto address = socketBindListen(config, socket, interserver_listen_host, port);
socket.setReceiveTimeout(settings.http_receive_timeout);
socket.setSendTimeout(settings.http_send_timeout);
socket.setReceiveTimeout(settings[Setting::http_receive_timeout]);
socket.setSendTimeout(settings[Setting::http_send_timeout]);
return ProtocolServerAdapter(
interserver_listen_host,
port_name,
@ -2728,8 +2747,8 @@ void Server::createInterserverServers(
#if USE_SSL
Poco::Net::SecureServerSocket socket;
auto address = socketBindListen(config, socket, interserver_listen_host, port, /* secure = */ true);
socket.setReceiveTimeout(settings.http_receive_timeout);
socket.setSendTimeout(settings.http_send_timeout);
socket.setReceiveTimeout(settings[Setting::http_receive_timeout]);
socket.setSendTimeout(settings[Setting::http_send_timeout]);
return ProtocolServerAdapter(
interserver_listen_host,
port_name,

View File

@ -1,10 +1,17 @@
#include <Access/ContextAccessParams.h>
#include <Core/Settings.h>
#include <IO/Operators.h>
#include <Common/typeid_cast.h>
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_ddl;
extern const SettingsBool allow_introspection_functions;
extern const SettingsUInt64 readonly;
}
ContextAccessParams::ContextAccessParams(
std::optional<UUID> user_id_,
@ -18,9 +25,9 @@ ContextAccessParams::ContextAccessParams(
, full_access(full_access_)
, use_default_roles(use_default_roles_)
, current_roles(current_roles_)
, readonly(settings_.readonly)
, allow_ddl(settings_.allow_ddl)
, allow_introspection(settings_.allow_introspection_functions)
, readonly(settings_[Setting::readonly])
, allow_ddl(settings_[Setting::allow_ddl])
, allow_introspection(settings_[Setting::allow_introspection_functions])
, current_database(current_database_)
, interface(client_info_.interface)
, http_method(client_info_.http_method)

View File

@ -10,10 +10,15 @@
#include <Common/SettingSource.h>
#include <IO/WriteHelpers.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <boost/range/algorithm_ext/erase.hpp>
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_ddl;
extern const SettingsUInt64 readonly;
}
namespace ErrorCodes
{
extern const int READONLY;
@ -164,7 +169,7 @@ void SettingsConstraints::check(const Settings & current_settings, const Setting
if (element.writability)
new_value = *element.writability;
auto setting_name = Settings::Traits::resolveName(element.setting_name);
auto setting_name = Settings::resolveName(element.setting_name);
auto it = constraints.find(setting_name);
if (it != constraints.end())
old_value = it->second.writability;
@ -255,7 +260,7 @@ bool SettingsConstraints::checkImpl(const Settings & current_settings,
ReactionOnViolation reaction,
SettingSource source) const
{
std::string_view setting_name = Settings::Traits::resolveName(change.name);
std::string_view setting_name = Settings::resolveName(change.name);
if (setting_name == "profile")
return true;
@ -393,7 +398,7 @@ std::string_view SettingsConstraints::resolveSettingNameWithCache(std::string_vi
SettingsConstraints::Checker SettingsConstraints::getChecker(const Settings & current_settings, std::string_view setting_name) const
{
auto resolved_name = resolveSettingNameWithCache(setting_name);
if (!current_settings.allow_ddl && resolved_name == "allow_ddl")
if (!current_settings[Setting::allow_ddl] && resolved_name == "allow_ddl")
return Checker(PreformattedMessage::create("Cannot modify 'allow_ddl' setting when DDL queries are prohibited for the user"),
ErrorCodes::QUERY_IS_PROHIBITED);
@ -403,11 +408,11 @@ SettingsConstraints::Checker SettingsConstraints::getChecker(const Settings & cu
* 2 - only read requests, as well as changing settings, except for the `readonly` setting.
*/
if (current_settings.readonly > 1 && resolved_name == "readonly")
if (current_settings[Setting::readonly] > 1 && resolved_name == "readonly")
return Checker(PreformattedMessage::create("Cannot modify 'readonly' setting in readonly mode"), ErrorCodes::READONLY);
auto it = constraints.find(resolved_name);
if (current_settings.readonly == 1)
if (current_settings[Setting::readonly] == 1)
{
if (it == constraints.end() || it->second.writability != SettingConstraintWritability::CHANGEABLE_IN_READONLY)
return Checker(PreformattedMessage::create("Cannot modify '{}' setting in readonly mode", setting_name),
@ -416,9 +421,9 @@ SettingsConstraints::Checker SettingsConstraints::getChecker(const Settings & cu
else // For both readonly=0 and readonly=2
{
if (it == constraints.end())
return Checker(Settings::Traits::resolveName); // Allowed
return Checker(Settings::resolveName); // Allowed
}
return Checker(it->second, Settings::Traits::resolveName);
return Checker(it->second, Settings::resolveName);
}
SettingsConstraints::Checker SettingsConstraints::getMergeTreeChecker(std::string_view short_name) const

View File

@ -249,7 +249,7 @@ bool SettingsProfileElements::isBackupAllowed() const
bool SettingsProfileElements::isAllowBackupSetting(const String & setting_name)
{
static constexpr std::string_view ALLOW_BACKUP_SETTING_NAME = "allow_backup";
return Settings::Traits::resolveName(setting_name) == ALLOW_BACKUP_SETTING_NAME;
return Settings::resolveName(setting_name) == ALLOW_BACKUP_SETTING_NAME;
}
}

View File

@ -1,4 +1,4 @@
if (TARGET ch_contrib::krb5)
clickhouse_add_executable (kerberos_init kerberos_init.cpp)
target_link_libraries (kerberos_init PRIVATE dbms ch_contrib::krb5)
target_link_libraries (kerberos_init PRIVATE dbms clickhouse_functions ch_contrib::krb5)
endif()

View File

@ -46,14 +46,6 @@ inline Field settingCastValueUtil(std::string_view full_name, const Field & valu
});
}
inline String settingValueToStringUtil(std::string_view full_name, const Field & value)
{
return resolveSetting(full_name, [&] <typename T> (std::string_view short_name, SettingsType<T>)
{
return T::valueToStringUtil(short_name, value);
});
}
inline Field settingStringToValueUtil(std::string_view full_name, const String & str)
{
return resolveSetting(full_name, [&] <typename T> (std::string_view short_name, SettingsType<T>)
@ -89,10 +81,9 @@ inline String settingFullName<MergeTreeSettings>(std::string_view short_name)
inline std::string resolveSettingName(std::string_view full_name)
{
return resolveSetting(full_name, [&] <typename T> (std::string_view short_name, SettingsType<T>)
{
return settingFullName<T>(T::Traits::resolveName(short_name));
});
return resolveSetting(
full_name,
[&]<typename T>(std::string_view short_name, SettingsType<T>) { return settingFullName<T>(T::resolveName(short_name)); });
}
}

View File

@ -14,6 +14,10 @@ static constexpr size_t MAX_AGGREGATE_FUNCTION_NAME_LENGTH = 1000;
namespace DB
{
struct Settings;
namespace Setting
{
extern const SettingsBool log_queries;
}
namespace ErrorCodes
{
@ -199,7 +203,7 @@ AggregateFunctionPtr AggregateFunctionFactory::getImpl(
found = *opt;
out_properties = found.properties;
if (query_context && query_context->getSettingsRef().log_queries)
if (query_context && query_context->getSettingsRef()[Setting::log_queries])
query_context->addQueryFactoriesInfo(
Context::QueryLogFactories::AggregateFunction, is_case_insensitive ? case_insensitive_name : name);
@ -224,7 +228,7 @@ AggregateFunctionPtr AggregateFunctionFactory::getImpl(
"Aggregate function combinator '{}' is only for internal usage",
combinator_name);
if (query_context && query_context->getSettingsRef().log_queries)
if (query_context && query_context->getSettingsRef()[Setting::log_queries])
query_context->addQueryFactoriesInfo(Context::QueryLogFactories::AggregateFunctionCombinator, combinator_name);
String nested_name = name.substr(0, name.size() - combinator_name.size());

View File

@ -17,6 +17,12 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_introspection_functions;
}
namespace ErrorCodes
{
extern const int FUNCTION_NOT_ALLOWED;
@ -628,7 +634,7 @@ static void check(const std::string & name, const DataTypes & argument_types, co
AggregateFunctionPtr createAggregateFunctionFlameGraph(const std::string & name, const DataTypes & argument_types, const Array & params, const Settings * settings)
{
if (!settings->allow_introspection_functions)
if (!(*settings)[Setting::allow_introspection_functions])
throw Exception(ErrorCodes::FUNCTION_NOT_ALLOWED,
"Introspection functions are disabled, because setting 'allow_introspection_functions' is set to 0");

View File

@ -18,15 +18,19 @@
#include <Common/assert_cast.h>
#include <AggregateFunctions/IAggregateFunction.h>
#include <base/range.h>
#include <bitset>
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_experimental_funnel_functions;
}
constexpr size_t max_events_size = 64;
constexpr size_t min_required_args = 3;
namespace ErrorCodes
@ -448,7 +452,7 @@ inline AggregateFunctionPtr createAggregateFunctionSequenceNodeImpl(
AggregateFunctionPtr
createAggregateFunctionSequenceNode(const std::string & name, const DataTypes & argument_types, const Array & parameters, const Settings * settings)
{
if (settings == nullptr || !settings->allow_experimental_funnel_functions)
if (settings == nullptr || !(*settings)[Setting::allow_experimental_funnel_functions])
{
throw Exception(ErrorCodes::UNKNOWN_AGGREGATE_FUNCTION, "Aggregate function {} is experimental. "
"Set `allow_experimental_funnel_functions` setting to enable it", name);

View File

@ -15,7 +15,10 @@
namespace DB
{
struct Settings;
namespace Setting
{
extern const SettingsMaxThreads max_threads;
}
namespace ErrorCodes
{
@ -149,7 +152,7 @@ void registerAggregateFunctionsUniq(AggregateFunctionFactory & factory)
auto assign_bool_param = [](const std::string & name, const DataTypes & argument_types, const Array & params, const Settings * settings)
{
/// Using two level hash set if we wouldn't be able to merge in parallel can cause ~10% slowdown.
if (settings && settings->max_threads > 1)
if (settings && (*settings)[Setting::max_threads] > 1)
return createAggregateFunctionUniq<
true, AggregateFunctionUniqExactData, AggregateFunctionUniqExactDataForVariadic, true /* is_able_to_parallelize_merge */>(name, argument_types, params, settings);
else

View File

@ -3,6 +3,7 @@
#include <Core/Settings.h>
#include <DataTypes/DataTypeDate.h>
#include <DataTypes/DataTypeDateTime.h>
#include <base/range.h>
#include <unordered_set>
#include <Columns/ColumnsNumber.h>

View File

@ -1,5 +1,5 @@
clickhouse_add_executable (quantile-t-digest quantile-t-digest.cpp)
target_link_libraries (quantile-t-digest PRIVATE dbms clickhouse_aggregate_functions)
target_link_libraries (quantile-t-digest PRIVATE dbms clickhouse_functions clickhouse_aggregate_functions)
clickhouse_add_executable (group_array_sorted group_array_sorted.cpp)
target_link_libraries (group_array_sorted PRIVATE dbms clickhouse_aggregate_functions)
target_link_libraries (group_array_sorted PRIVATE dbms clickhouse_functions clickhouse_aggregate_functions)

View File

@ -14,6 +14,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_aggregators_of_group_by_keys;
}
namespace ErrorCodes
{
@ -34,7 +38,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_aggregators_of_group_by_keys)
if (!getSettings()[Setting::optimize_aggregators_of_group_by_keys])
return;
/// Collect group by keys.
@ -79,7 +83,7 @@ public:
/// Now we visit all nodes in QueryNode, we should remove group_by_keys from stack.
void leaveImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_aggregators_of_group_by_keys)
if (!getSettings()[Setting::optimize_aggregators_of_group_by_keys])
return;
if (node->getNodeType() == QueryTreeNodeType::FUNCTION)

View File

@ -15,6 +15,11 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_arithmetic_operations_in_aggregate_functions;
}
namespace ErrorCodes
{
@ -56,7 +61,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_arithmetic_operations_in_aggregate_functions)
if (!getSettings()[Setting::optimize_arithmetic_operations_in_aggregate_functions])
return;
auto * aggregate_function_node = node->as<FunctionNode>();

View File

@ -15,6 +15,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_rewrite_array_exists_to_has;
}
namespace
{
@ -27,7 +31,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_rewrite_array_exists_to_has)
if (!getSettings()[Setting::optimize_rewrite_array_exists_to_has])
return;
auto * array_exists_function_node = node->as<FunctionNode>();

View File

@ -12,6 +12,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool final;
}
namespace
{
@ -24,7 +28,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().final)
if (!getSettings()[Setting::final])
return;
const auto * query_node = node->as<QueryNode>();

View File

@ -26,6 +26,14 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_hyperscan;
extern const SettingsUInt64 max_hyperscan_regexp_length;
extern const SettingsUInt64 max_hyperscan_regexp_total_length;
extern const SettingsBool reject_expensive_hyperscan_regexps;
extern const SettingsBool optimize_or_like_chain;
}
namespace
{
@ -48,10 +56,8 @@ public:
{
const auto & settings = getSettings();
return settings.optimize_or_like_chain
&& settings.allow_hyperscan
&& settings.max_hyperscan_regexp_length == 0
&& settings.max_hyperscan_regexp_total_length == 0;
return settings[Setting::optimize_or_like_chain] && settings[Setting::allow_hyperscan] && settings[Setting::max_hyperscan_regexp_length] == 0
&& settings[Setting::max_hyperscan_regexp_total_length] == 0;
}
void enterImpl(QueryTreeNodePtr & node)
@ -139,7 +145,11 @@ private:
void ConvertOrLikeChainPass::run(QueryTreeNodePtr & query_tree_node, ContextPtr context)
{
const auto & settings = context->getSettingsRef();
auto match_function_resolver = createInternalMultiMatchAnyOverloadResolver(settings.allow_hyperscan, settings.max_hyperscan_regexp_length, settings.max_hyperscan_regexp_total_length, settings.reject_expensive_hyperscan_regexps);
auto match_function_resolver = createInternalMultiMatchAnyOverloadResolver(
settings[Setting::allow_hyperscan],
settings[Setting::max_hyperscan_regexp_length],
settings[Setting::max_hyperscan_regexp_total_length],
settings[Setting::reject_expensive_hyperscan_regexps]);
auto or_function_resolver = createInternalFunctionOrOverloadResolver();
ConvertOrLikeChainVisitor visitor(std::move(or_function_resolver), std::move(match_function_resolver), std::move(context));

View File

@ -19,6 +19,13 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool convert_query_to_cnf;
extern const SettingsBool optimize_append_index;
extern const SettingsBool optimize_substitute_columns;
extern const SettingsBool optimize_using_constraints;
}
namespace
{
@ -681,7 +688,7 @@ void optimizeWithConstraints(Analyzer::CNF & cnf, const QueryTreeNodes & table_e
cnf.pushNotIntoFunctions(context);
const auto & settings = context->getSettingsRef();
if (settings.optimize_append_index)
if (settings[Setting::optimize_append_index])
addIndexConstraint(cnf, table_expressions, context);
}
@ -693,7 +700,7 @@ void optimizeNode(QueryTreeNodePtr & node, const QueryTreeNodes & table_expressi
if (!cnf)
return;
if (settings.optimize_using_constraints)
if (settings[Setting::optimize_using_constraints])
optimizeWithConstraints(*cnf, table_expressions, context);
auto new_node = cnf->toQueryTree();
@ -731,7 +738,7 @@ public:
optimize_filter(query_node->getPrewhere());
optimize_filter(query_node->getHaving());
if (has_filter && settings.optimize_substitute_columns)
if (has_filter && settings[Setting::optimize_substitute_columns])
substituteColumns(*query_node, table_expressions, context);
}
};
@ -741,7 +748,7 @@ public:
void ConvertLogicalExpressionToCNFPass::run(QueryTreeNodePtr & query_tree_node, ContextPtr context)
{
const auto & settings = context->getSettingsRef();
if (!settings.convert_query_to_cnf)
if (!settings[Setting::convert_query_to_cnf])
return;
ConvertQueryToCNFVisitor visitor(std::move(context));

View File

@ -15,6 +15,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool count_distinct_optimization;
}
namespace
{
@ -27,7 +31,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().count_distinct_optimization)
if (!getSettings()[Setting::count_distinct_optimization])
return;
auto * query_node = node->as<QueryNode>();

View File

@ -21,6 +21,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 cross_to_inner_join_rewrite;
}
namespace ErrorCodes
{
@ -193,17 +197,14 @@ public:
}
private:
bool isEnabled() const
{
return getSettings().cross_to_inner_join_rewrite;
}
bool isEnabled() const { return getSettings()[Setting::cross_to_inner_join_rewrite]; }
bool forceRewrite(JoinKind kind) const
{
if (kind == JoinKind::Cross)
return false;
/// Comma join can be forced to rewrite
return getSettings().cross_to_inner_join_rewrite >= 2;
return getSettings()[Setting::cross_to_inner_join_rewrite] >= 2;
}
QueryTreeNodePtr makeConjunction(const QueryTreeNodes & nodes)

View File

@ -25,6 +25,12 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool group_by_use_nulls;
extern const SettingsBool join_use_nulls;
extern const SettingsBool optimize_functions_to_subcolumns;
}
namespace
{
@ -257,7 +263,7 @@ public:
void enterImpl(const QueryTreeNodePtr & node)
{
if (!getSettings().optimize_functions_to_subcolumns)
if (!getSettings()[Setting::optimize_functions_to_subcolumns])
return;
if (auto * table_node = node->as<TableNode>())
@ -281,14 +287,14 @@ public:
if (const auto * join_node = node->as<JoinNode>())
{
can_wrap_result_columns_with_nullable |= getContext()->getSettingsRef().join_use_nulls;
can_wrap_result_columns_with_nullable |= getContext()->getSettingsRef()[Setting::join_use_nulls];
return;
}
if (const auto * query_node = node->as<QueryNode>())
{
if (query_node->isGroupByWithCube() || query_node->isGroupByWithRollup() || query_node->isGroupByWithGroupingSets())
can_wrap_result_columns_with_nullable |= getContext()->getSettingsRef().group_by_use_nulls;
can_wrap_result_columns_with_nullable |= getContext()->getSettingsRef()[Setting::group_by_use_nulls];
return;
}
}
@ -419,7 +425,7 @@ public:
void enterImpl(QueryTreeNodePtr & node) const
{
if (!getSettings().optimize_functions_to_subcolumns)
if (!getSettings()[Setting::optimize_functions_to_subcolumns])
return;
auto [function_node, first_argument_column_node, table_node] = getTypedNodesForOptimization(node, getContext());

View File

@ -21,6 +21,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_syntax_fuse_functions;
}
namespace ErrorCodes
{
@ -44,7 +48,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_syntax_fuse_functions)
if (!getSettings()[Setting::optimize_syntax_fuse_functions])
return;
auto * function_node = node->as<FunctionNode>();

View File

@ -15,6 +15,11 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool force_grouping_standard_compatibility;
extern const SettingsBool group_by_use_nulls;
}
namespace ErrorCodes
{
@ -72,41 +77,38 @@ public:
FunctionOverloadResolverPtr grouping_function_resolver;
bool add_grouping_set_column = false;
bool force_grouping_standard_compatibility = getSettings().force_grouping_standard_compatibility;
bool force_grouping_standard_compatibility = getSettings()[Setting::force_grouping_standard_compatibility];
size_t aggregation_keys_size = aggregation_key_to_index.size();
switch (group_by_kind)
{
case GroupByKind::ORDINARY:
{
auto grouping_ordinary_function = std::make_shared<FunctionGroupingOrdinary>(arguments_indexes,
force_grouping_standard_compatibility);
auto grouping_ordinary_function
= std::make_shared<FunctionGroupingOrdinary>(arguments_indexes, force_grouping_standard_compatibility);
grouping_function_resolver = std::make_shared<FunctionToOverloadResolverAdaptor>(std::move(grouping_ordinary_function));
break;
}
case GroupByKind::ROLLUP:
{
auto grouping_rollup_function = std::make_shared<FunctionGroupingForRollup>(arguments_indexes,
aggregation_keys_size,
force_grouping_standard_compatibility);
auto grouping_rollup_function = std::make_shared<FunctionGroupingForRollup>(
arguments_indexes, aggregation_keys_size, force_grouping_standard_compatibility);
grouping_function_resolver = std::make_shared<FunctionToOverloadResolverAdaptor>(std::move(grouping_rollup_function));
add_grouping_set_column = true;
break;
}
case GroupByKind::CUBE:
{
auto grouping_cube_function = std::make_shared<FunctionGroupingForCube>(arguments_indexes,
aggregation_keys_size,
force_grouping_standard_compatibility);
auto grouping_cube_function = std::make_shared<FunctionGroupingForCube>(
arguments_indexes, aggregation_keys_size, force_grouping_standard_compatibility);
grouping_function_resolver = std::make_shared<FunctionToOverloadResolverAdaptor>(std::move(grouping_cube_function));
add_grouping_set_column = true;
break;
}
case GroupByKind::GROUPING_SETS:
{
auto grouping_grouping_sets_function = std::make_shared<FunctionGroupingForGroupingSets>(arguments_indexes,
grouping_sets_keys_indexes,
force_grouping_standard_compatibility);
auto grouping_grouping_sets_function = std::make_shared<FunctionGroupingForGroupingSets>(
arguments_indexes, grouping_sets_keys_indexes, force_grouping_standard_compatibility);
grouping_function_resolver = std::make_shared<FunctionToOverloadResolverAdaptor>(std::move(grouping_grouping_sets_function));
add_grouping_set_column = true;
break;
@ -147,7 +149,8 @@ void resolveGroupingFunctions(QueryTreeNodePtr & query_node, ContextPtr context)
if (query_node_typed.hasGroupBy())
{
/// It is expected by execution layer that if there are only 1 grouping set it will be removed
if (query_node_typed.isGroupByWithGroupingSets() && query_node_typed.getGroupBy().getNodes().size() == 1 && !context->getSettingsRef().group_by_use_nulls)
if (query_node_typed.isGroupByWithGroupingSets() && query_node_typed.getGroupBy().getNodes().size() == 1
&& !context->getSettingsRef()[Setting::group_by_use_nulls])
{
auto grouping_set_list_node = query_node_typed.getGroupBy().getNodes().front();
auto & grouping_set_list_node_typed = grouping_set_list_node->as<ListNode &>();

View File

@ -10,6 +10,13 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_execute_multiif_columnar;
extern const SettingsBool allow_experimental_variant_type;
extern const SettingsBool optimize_if_chain_to_multiif;
extern const SettingsBool use_variant_as_common_type;
}
namespace
{
@ -27,7 +34,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_if_chain_to_multiif)
if (!getSettings()[Setting::optimize_if_chain_to_multiif])
return;
auto * function_node = node->as<FunctionNode>();
@ -84,7 +91,8 @@ private:
void IfChainToMultiIfPass::run(QueryTreeNodePtr & query_tree_node, ContextPtr context)
{
const auto & settings = context->getSettingsRef();
auto multi_if_function_ptr = createInternalMultiIfOverloadResolver(settings.allow_execute_multiif_columnar, settings.allow_experimental_variant_type, settings.use_variant_as_common_type);
auto multi_if_function_ptr = createInternalMultiIfOverloadResolver(
settings[Setting::allow_execute_multiif_columnar], settings[Setting::allow_experimental_variant_type], settings[Setting::use_variant_as_common_type]);
IfChainToMultiIfPassVisitor visitor(std::move(multi_if_function_ptr), std::move(context));
visitor.visit(query_tree_node);
}

View File

@ -16,6 +16,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_if_transform_strings_to_enum;
}
namespace
{
@ -101,7 +105,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_if_transform_strings_to_enum)
if (!getSettings()[Setting::optimize_if_transform_strings_to_enum])
return;
auto * function_node = node->as<FunctionNode>();

View File

@ -16,6 +16,11 @@
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 optimize_min_equality_disjunction_chain_length;
extern const SettingsUInt64 optimize_min_inequality_conjunction_chain_length;
}
namespace ErrorCodes
{
@ -531,7 +536,8 @@ private:
for (auto & [expression, not_equals_functions] : node_to_not_equals_functions)
{
const auto & settings = getSettings();
if (not_equals_functions.size() < settings.optimize_min_inequality_conjunction_chain_length && !expression.node->getResultType()->lowCardinality())
if (not_equals_functions.size() < settings[Setting::optimize_min_inequality_conjunction_chain_length]
&& !expression.node->getResultType()->lowCardinality())
{
std::move(not_equals_functions.begin(), not_equals_functions.end(), std::back_inserter(and_operands));
continue;
@ -653,7 +659,8 @@ private:
for (auto & [expression, equals_functions] : node_to_equals_functions)
{
const auto & settings = getSettings();
if (equals_functions.size() < settings.optimize_min_equality_disjunction_chain_length && !expression.node->getResultType()->lowCardinality())
if (equals_functions.size() < settings[Setting::optimize_min_equality_disjunction_chain_length]
&& !expression.node->getResultType()->lowCardinality())
{
std::move(equals_functions.begin(), equals_functions.end(), std::back_inserter(or_operands));
continue;

View File

@ -8,6 +8,12 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_experimental_variant_type;
extern const SettingsBool optimize_multiif_to_if;
extern const SettingsBool use_variant_as_common_type;
}
namespace
{
@ -25,7 +31,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_multiif_to_if)
if (!getSettings()[Setting::optimize_multiif_to_if])
return;
auto * function_node = node->as<FunctionNode>();
@ -57,7 +63,8 @@ private:
void MultiIfToIfPass::run(QueryTreeNodePtr & query_tree_node, ContextPtr context)
{
const auto & settings = context->getSettingsRef();
auto if_function_ptr = createInternalFunctionIfOverloadResolver(settings.allow_experimental_variant_type, settings.use_variant_as_common_type);
auto if_function_ptr
= createInternalFunctionIfOverloadResolver(settings[Setting::allow_experimental_variant_type], settings[Setting::use_variant_as_common_type]);
MultiIfToIfVisitor visitor(std::move(if_function_ptr), std::move(context));
visitor.visit(query_tree_node);
}

View File

@ -13,6 +13,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_normalize_count_variants;
}
namespace
{
@ -25,7 +29,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_normalize_count_variants)
if (!getSettings()[Setting::optimize_normalize_count_variants])
return;
auto * function_node = node->as<FunctionNode>();

View File

@ -13,6 +13,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_time_filter_with_preimage;
}
namespace ErrorCodes
{
@ -58,7 +62,7 @@ public:
{"greaterOrEquals", "lessOrEquals"},
};
if (!getSettings().optimize_time_filter_with_preimage)
if (!getSettings()[Setting::optimize_time_filter_with_preimage])
return;
const auto * function = node->as<FunctionNode>();

View File

@ -12,6 +12,11 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool group_by_use_nulls;
extern const SettingsBool optimize_group_by_function_keys;
}
class OptimizeGroupByFunctionKeysVisitor : public InDepthQueryTreeVisitorWithContext<OptimizeGroupByFunctionKeysVisitor>
{
@ -29,13 +34,13 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_group_by_function_keys)
if (!getSettings()[Setting::optimize_group_by_function_keys])
return;
/// When group_by_use_nulls = 1 removing keys from GROUP BY can lead
/// to unexpected types in some functions.
/// See example in https://github.com/ClickHouse/ClickHouse/pull/61567#issuecomment-2018007887
if (getSettings().group_by_use_nulls)
if (getSettings()[Setting::group_by_use_nulls])
return;
auto * query = node->as<QueryNode>();

View File

@ -9,6 +9,11 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool group_by_use_nulls;
extern const SettingsBool optimize_injective_functions_in_group_by;
}
namespace
{
@ -23,14 +28,14 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_injective_functions_in_group_by)
if (!getSettings()[Setting::optimize_injective_functions_in_group_by])
return;
/// Don't optimize injective functions when group_by_use_nulls=true,
/// because in this case we make initial group by keys Nullable
/// and eliminating some functions can cause issues with arguments Nullability
/// during their execution. See examples in https://github.com/ClickHouse/ClickHouse/pull/61567#issuecomment-2008181143
if (getSettings().group_by_use_nulls)
if (getSettings()[Setting::group_by_use_nulls])
return;
auto * query = node->as<QueryNode>();

View File

@ -12,6 +12,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_redundant_functions_in_order_by;
}
namespace
{
@ -31,7 +35,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_redundant_functions_in_order_by)
if (!getSettings()[Setting::optimize_redundant_functions_in_order_by])
return;
auto * query = node->as<QueryNode>();

View File

@ -20,6 +20,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_rewrite_aggregate_function_with_if;
}
namespace
{
@ -32,7 +36,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_rewrite_aggregate_function_with_if)
if (!getSettings()[Setting::optimize_rewrite_aggregate_function_with_if])
return;
auto * function_node = node->as<FunctionNode>();

View File

@ -11,6 +11,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_arithmetic_operations_in_aggregate_functions;
}
namespace
{
@ -23,7 +27,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_arithmetic_operations_in_aggregate_functions)
if (!getSettings()[Setting::optimize_arithmetic_operations_in_aggregate_functions])
return;
static const std::unordered_set<String> func_supported = {

View File

@ -14,6 +14,11 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool aggregate_functions_null_for_empty;
extern const SettingsBool optimize_rewrite_sum_if_to_count_if;
}
namespace
{
@ -26,7 +31,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_rewrite_sum_if_to_count_if)
if (!getSettings()[Setting::optimize_rewrite_sum_if_to_count_if])
return;
auto * function_node = node->as<FunctionNode>();
@ -56,7 +61,7 @@ public:
return;
const auto & constant_value_literal = constant_node->getValue();
if (getSettings().aggregate_functions_null_for_empty)
if (getSettings()[Setting::aggregate_functions_null_for_empty])
return;
/// Rewrite `sumIf(1, cond)` into `countIf(cond)`

View File

@ -14,6 +14,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_injective_functions_inside_uniq;
}
namespace
{
@ -36,7 +40,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_injective_functions_inside_uniq)
if (!getSettings()[Setting::optimize_injective_functions_inside_uniq])
return;
auto * function_node = node->as<FunctionNode>();

View File

@ -13,6 +13,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool optimize_uniq_to_count;
}
namespace
{
@ -123,7 +127,7 @@ public:
void enterImpl(QueryTreeNodePtr & node)
{
if (!getSettings().optimize_uniq_to_count)
if (!getSettings()[Setting::optimize_uniq_to_count])
return;
auto * query_node = node->as<QueryNode>();

View File

@ -50,6 +50,17 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_experimental_variant_type;
extern const SettingsBool any_join_distinct_right_table_keys;
extern const SettingsJoinStrictness join_default_strictness;
extern const SettingsBool enable_order_by_all;
extern const SettingsUInt64 limit;
extern const SettingsUInt64 offset;
extern const SettingsBool use_variant_as_common_type;
}
namespace ErrorCodes
{
@ -235,13 +246,13 @@ QueryTreeNodePtr QueryTreeBuilder::buildSelectExpression(const ASTPtr & select_q
UInt64 offset = 0;
/// Remove global settings limit and offset
if (const auto & settings_ref = updated_context->getSettingsRef(); settings_ref.limit || settings_ref.offset)
if (const auto & settings_ref = updated_context->getSettingsRef(); settings_ref[Setting::limit] || settings_ref[Setting::offset])
{
Settings settings = updated_context->getSettingsCopy();
limit = settings.limit;
offset = settings.offset;
settings.limit = 0;
settings.offset = 0;
limit = settings[Setting::limit];
offset = settings[Setting::offset];
settings[Setting::limit] = 0;
settings[Setting::offset] = 0;
updated_context->setSettings(settings);
}
@ -268,7 +279,7 @@ QueryTreeNodePtr QueryTreeBuilder::buildSelectExpression(const ASTPtr & select_q
}
}
const auto enable_order_by_all = updated_context->getSettingsRef().enable_order_by_all;
const auto enable_order_by_all = updated_context->getSettingsRef()[Setting::enable_order_by_all];
auto current_query_tree = std::make_shared<QueryNode>(std::move(updated_context), std::move(settings_changes));
@ -577,7 +588,7 @@ QueryTreeNodePtr QueryTreeBuilder::buildExpression(const ASTPtr & expression, co
}
else if (const auto * ast_literal = expression->as<ASTLiteral>())
{
if (context->getSettingsRef().allow_experimental_variant_type && context->getSettingsRef().use_variant_as_common_type)
if (context->getSettingsRef()[Setting::allow_experimental_variant_type] && context->getSettingsRef()[Setting::use_variant_as_common_type])
result = std::make_shared<ConstantNode>(ast_literal->value, applyVisitor(FieldToDataType<LeastSupertypeOnError::Variant>(), ast_literal->value));
else
result = std::make_shared<ConstantNode>(ast_literal->value);
@ -908,8 +919,8 @@ QueryTreeNodePtr QueryTreeBuilder::buildJoinTree(const ASTPtr & tables_in_select
join_expression = buildExpression(table_join.on_expression, context);
const auto & settings = context->getSettingsRef();
auto join_default_strictness = settings.join_default_strictness;
auto any_join_distinct_right_table_keys = settings.any_join_distinct_right_table_keys;
auto join_default_strictness = settings[Setting::join_default_strictness];
auto any_join_distinct_right_table_keys = settings[Setting::any_join_distinct_right_table_keys];
JoinStrictness result_join_strictness = table_join.strictness;
JoinKind result_join_kind = table_join.kind;

View File

@ -7,6 +7,12 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool group_by_use_nulls;
extern const SettingsBool join_use_nulls;
}
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
@ -32,12 +38,12 @@ IdentifierResolveScope::IdentifierResolveScope(QueryTreeNodePtr scope_node_, Ide
else if (auto * query_node = scope_node->as<QueryNode>())
{
context = query_node->getContext();
group_by_use_nulls = context->getSettingsRef().group_by_use_nulls &&
(query_node->isGroupByWithGroupingSets() || query_node->isGroupByWithRollup() || query_node->isGroupByWithCube());
group_by_use_nulls = context->getSettingsRef()[Setting::group_by_use_nulls]
&& (query_node->isGroupByWithGroupingSets() || query_node->isGroupByWithRollup() || query_node->isGroupByWithCube());
}
if (context)
join_use_nulls = context->getSettingsRef().join_use_nulls;
join_use_nulls = context->getSettingsRef()[Setting::join_use_nulls];
else if (parent_scope)
join_use_nulls = parent_scope->join_use_nulls;

View File

@ -30,6 +30,12 @@
namespace DB
{
namespace Setting
{
extern const SettingsSeconds lock_acquire_timeout;
extern const SettingsBool single_join_prefer_left_table;
}
namespace ErrorCodes
{
extern const int UNKNOWN_IDENTIFIER;
@ -420,7 +426,7 @@ QueryTreeNodePtr IdentifierResolver::tryResolveTableIdentifierFromDatabaseCatalo
if (!storage)
return {};
auto storage_lock = storage->lockForShare(context->getInitialQueryId(), context->getSettingsRef().lock_acquire_timeout);
auto storage_lock = storage->lockForShare(context->getInitialQueryId(), context->getSettingsRef()[Setting::lock_acquire_timeout]);
auto storage_snapshot = storage->getStorageSnapshot(storage->getInMemoryMetadataPtr(), context);
auto result = std::make_shared<TableNode>(std::move(storage), std::move(storage_lock), std::move(storage_snapshot));
if (is_temporary_table)
@ -1155,7 +1161,7 @@ QueryTreeNodePtr IdentifierResolver::tryResolveIdentifierFromJoin(const Identifi
resolved_identifier = left_resolved_identifier;
}
}
else if (scope.joins_count == 1 && scope.context->getSettingsRef().single_join_prefer_left_table)
else if (scope.joins_count == 1 && scope.context->getSettingsRef()[Setting::single_join_prefer_left_table])
{
resolved_side = JoinTableSide::Left;
resolved_identifier = left_resolved_identifier;

View File

@ -77,6 +77,35 @@ namespace ProfileEvents
namespace DB
{
namespace Setting
{
extern const SettingsBool aggregate_functions_null_for_empty;
extern const SettingsBool analyzer_compatibility_join_using_top_level_identifier;
extern const SettingsBool asterisk_include_alias_columns;
extern const SettingsBool asterisk_include_materialized_columns;
extern const SettingsString count_distinct_implementation;
extern const SettingsBool enable_global_with_statement;
extern const SettingsBool enable_order_by_all;
extern const SettingsBool enable_positional_arguments;
extern const SettingsBool enable_scalar_subquery_optimization;
extern const SettingsBool extremes;
extern const SettingsBool force_grouping_standard_compatibility;
extern const SettingsBool format_display_secrets_in_show_and_select;
extern const SettingsBool joined_subquery_requires_alias;
extern const SettingsUInt64 max_bytes_in_set;
extern const SettingsUInt64 max_expanded_ast_elements;
extern const SettingsUInt64 max_result_rows;
extern const SettingsUInt64 max_rows_in_set;
extern const SettingsUInt64 max_subquery_depth;
extern const SettingsBool prefer_column_name_to_alias;
extern const SettingsBool rewrite_count_distinct_if_with_count_distinct_implementation;
extern const SettingsOverflowMode set_overflow_mode;
extern const SettingsBool single_join_prefer_left_table;
extern const SettingsBool transform_null_in;
extern const SettingsUInt64 use_structure_from_insertion_table_in_table_functions;
}
namespace ErrorCodes
{
extern const int UNSUPPORTED_METHOD;
@ -506,8 +535,8 @@ void QueryAnalyzer::evaluateScalarSubqueryIfNeeded(QueryTreeNodePtr & node, Iden
auto subquery_context = Context::createCopy(context);
Settings subquery_settings = context->getSettingsCopy();
subquery_settings.max_result_rows = 1;
subquery_settings.extremes = false;
subquery_settings[Setting::max_result_rows] = 1;
subquery_settings[Setting::extremes] = false;
subquery_context->setSettings(subquery_settings);
/// When execute `INSERT INTO t WITH ... SELECT ...`, it may lead to `Unknown columns`
/// exception with this settings enabled(https://github.com/ClickHouse/ClickHouse/issues/52494).
@ -627,10 +656,8 @@ void QueryAnalyzer::evaluateScalarSubqueryIfNeeded(QueryTreeNodePtr & node, Iden
auto * nearest_query_scope = scope.getNearestQueryScope();
/// Always convert to literals when there is no query context
if (!context->getSettingsRef().enable_scalar_subquery_optimization ||
!useless_literal_types.contains(scalar_type_name) ||
!context->hasQueryContext() ||
!nearest_query_scope)
if (!context->getSettingsRef()[Setting::enable_scalar_subquery_optimization] || !useless_literal_types.contains(scalar_type_name)
|| !context->hasQueryContext() || !nearest_query_scope)
{
auto constant_value = std::make_shared<ConstantValue>(std::move(scalar_value), scalar_type);
auto constant_node = std::make_shared<ConstantNode>(constant_value, node);
@ -726,7 +753,7 @@ void QueryAnalyzer::mergeWindowWithParentWindow(const QueryTreeNodePtr & window_
void QueryAnalyzer::replaceNodesWithPositionalArguments(QueryTreeNodePtr & node_list, const QueryTreeNodes & projection_nodes, IdentifierResolveScope & scope)
{
const auto & settings = scope.context->getSettingsRef();
if (!settings.enable_positional_arguments || scope.context->getClientInfo().query_kind != ClientInfo::QueryKind::INITIAL_QUERY)
if (!settings[Setting::enable_positional_arguments] || scope.context->getClientInfo().query_kind != ClientInfo::QueryKind::INITIAL_QUERY)
return;
auto & node_list_typed = node_list->as<ListNode &>();
@ -843,7 +870,7 @@ void QueryAnalyzer::validateTableExpressionModifiers(const QueryTreeNodePtr & ta
void QueryAnalyzer::validateJoinTableExpressionWithoutAlias(const QueryTreeNodePtr & join_node, const QueryTreeNodePtr & table_expression_node, IdentifierResolveScope & scope)
{
if (!scope.context->getSettingsRef().joined_subquery_requires_alias)
if (!scope.context->getSettingsRef()[Setting::joined_subquery_requires_alias])
return;
bool table_expression_has_alias = table_expression_node->hasAlias();
@ -938,7 +965,7 @@ void QueryAnalyzer::expandGroupByAll(QueryNode & query_tree_node_typed)
void QueryAnalyzer::expandOrderByAll(QueryNode & query_tree_node_typed, const Settings & settings)
{
if (!settings.enable_order_by_all || !query_tree_node_typed.isOrderByAll())
if (!settings[Setting::enable_order_by_all] || !query_tree_node_typed.isOrderByAll())
return;
auto * all_node = query_tree_node_typed.getOrderBy().getNodes()[0]->as<SortNode>();
@ -989,12 +1016,14 @@ std::string QueryAnalyzer::rewriteAggregateFunctionNameIfNeeded(
if (aggregate_function_name_lowercase == "countdistinct")
{
result_aggregate_function_name = settings.count_distinct_implementation;
result_aggregate_function_name = settings[Setting::count_distinct_implementation];
}
else if (aggregate_function_name_lowercase == "countifdistinct" ||
(settings.rewrite_count_distinct_if_with_count_distinct_implementation && aggregate_function_name_lowercase == "countdistinctif"))
else if (
aggregate_function_name_lowercase == "countifdistinct"
|| (settings[Setting::rewrite_count_distinct_if_with_count_distinct_implementation]
&& aggregate_function_name_lowercase == "countdistinctif"))
{
result_aggregate_function_name = settings.count_distinct_implementation;
result_aggregate_function_name = settings[Setting::count_distinct_implementation];
result_aggregate_function_name += "If";
}
else if (aggregate_function_name_lowercase.ends_with("ifdistinct"))
@ -1004,7 +1033,7 @@ std::string QueryAnalyzer::rewriteAggregateFunctionNameIfNeeded(
result_aggregate_function_name = result_aggregate_function_name.substr(0, prefix_length) + "DistinctIf";
}
bool need_add_or_null = settings.aggregate_functions_null_for_empty && !result_aggregate_function_name.ends_with("OrNull");
bool need_add_or_null = settings[Setting::aggregate_functions_null_for_empty] && !result_aggregate_function_name.ends_with("OrNull");
if (need_add_or_null)
{
auto properties = AggregateFunctionFactory::instance().tryGetProperties(result_aggregate_function_name, action);
@ -1215,7 +1244,7 @@ IdentifierResolveResult QueryAnalyzer::tryResolveIdentifierInParentScopes(const
}
}
if (!scope.context->getSettingsRef().enable_global_with_statement)
if (!scope.context->getSettingsRef()[Setting::enable_global_with_statement])
return {};
/** Nested subqueries cannot access outer subqueries table expressions from JOIN tree because
@ -1347,7 +1376,7 @@ IdentifierResolveResult QueryAnalyzer::tryResolveIdentifier(const IdentifierLook
if (!resolve_result.resolved_identifier)
{
bool prefer_column_name_to_alias = scope.context->getSettingsRef().prefer_column_name_to_alias;
bool prefer_column_name_to_alias = scope.context->getSettingsRef()[Setting::prefer_column_name_to_alias];
if (identifier_lookup.isExpressionLookup())
{
@ -1558,10 +1587,10 @@ GetColumnsOptions QueryAnalyzer::buildGetColumnsOptions(QueryTreeNodePtr & match
const auto & settings = context->getSettingsRef();
if (settings.asterisk_include_alias_columns)
if (settings[Setting::asterisk_include_alias_columns])
get_columns_options_kind |= GetColumnsOptions::Kind::Aliases;
if (settings.asterisk_include_materialized_columns)
if (settings[Setting::asterisk_include_materialized_columns])
get_columns_options_kind |= GetColumnsOptions::Kind::Materialized;
}
@ -2810,7 +2839,7 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
allow_table_expressions /*allow_table_expression*/);
/// Mask arguments if needed
if (!scope.context->getSettingsRef().format_display_secrets_in_show_and_select)
if (!scope.context->getSettingsRef()[Setting::format_display_secrets_in_show_and_select])
{
if (FunctionSecretArgumentsFinder::Result secret_arguments = FunctionSecretArgumentsFinderTreeNode(*function_node_ptr).getResult(); secret_arguments.count)
{
@ -2834,7 +2863,7 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
if (is_special_function_in)
{
checkFunctionNodeHasEmptyNullsAction(function_node);
if (scope.context->getSettingsRef().transform_null_in)
if (scope.context->getSettingsRef()[Setting::transform_null_in])
{
static constexpr std::array<std::pair<std::string_view, std::string_view>, 4> in_function_to_replace_null_in_function_map =
{{
@ -3134,7 +3163,7 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
function_arguments_size);
checkFunctionNodeHasEmptyNullsAction(function_node);
bool force_grouping_standard_compatibility = scope.context->getSettingsRef().force_grouping_standard_compatibility;
bool force_grouping_standard_compatibility = scope.context->getSettingsRef()[Setting::force_grouping_standard_compatibility];
auto grouping_function = std::make_shared<FunctionGrouping>(force_grouping_standard_compatibility);
auto grouping_function_adaptor = std::make_shared<FunctionToOverloadResolverAdaptor>(std::move(grouping_function));
function_node.resolveAsFunction(grouping_function_adaptor->build(argument_columns));
@ -3388,14 +3417,12 @@ ProjectionNames QueryAnalyzer::resolveFunction(QueryTreeNodePtr & node, Identifi
const auto & settings = scope.context->getSettingsRef();
auto result_block = getSetElementsForConstantValue(first_argument_constant_type,
second_argument_constant_literal,
second_argument_constant_type,
settings.transform_null_in);
auto result_block = getSetElementsForConstantValue(
first_argument_constant_type, second_argument_constant_literal, second_argument_constant_type, settings[Setting::transform_null_in]);
SizeLimits size_limits_for_set = {settings.max_rows_in_set, settings.max_bytes_in_set, settings.set_overflow_mode};
SizeLimits size_limits_for_set = {settings[Setting::max_rows_in_set], settings[Setting::max_bytes_in_set], settings[Setting::set_overflow_mode]};
auto set = std::make_shared<Set>(size_limits_for_set, 0, settings.transform_null_in);
auto set = std::make_shared<Set>(size_limits_for_set, 0, settings[Setting::transform_null_in]);
set->setHeader(result_block.cloneEmpty().getColumnsWithTypeAndName());
set->insertFromBlock(result_block.getColumnsWithTypeAndName());
@ -3826,10 +3853,10 @@ ProjectionNames QueryAnalyzer::resolveExpressionNode(
}
}
validateTreeSize(node, scope.context->getSettingsRef().max_expanded_ast_elements, node_to_tree_size);
validateTreeSize(node, scope.context->getSettingsRef()[Setting::max_expanded_ast_elements], node_to_tree_size);
/// Lambda can be inside the aggregate function, so we should check parent scopes.
/// Most likely only the root scope can have an arrgegate function, but let's check all just in case.
/// Most likely only the root scope can have an aggregate function, but let's check all just in case.
bool in_aggregate_function_scope = false;
for (const auto * scope_ptr = &scope; scope_ptr; scope_ptr = scope_ptr->parent_scope)
in_aggregate_function_scope = in_aggregate_function_scope || scope_ptr->expressions_in_resolve_process_stack.hasAggregateFunction();
@ -4473,9 +4500,9 @@ void QueryAnalyzer::initializeTableExpressionData(const QueryTreeNodePtr & table
if (auto * scope_query_node = scope.scope_node->as<QueryNode>())
{
auto left_table_expression = extractLeftTableExpression(scope_query_node->getJoinTree());
if (table_expression_node.get() == left_table_expression.get() &&
scope.joins_count == 1 && scope.context->getSettingsRef().single_join_prefer_left_table)
table_expression_data.should_qualify_columns = false;
if (table_expression_node.get() == left_table_expression.get() && scope.joins_count == 1
&& scope.context->getSettingsRef()[Setting::single_join_prefer_left_table])
table_expression_data.should_qualify_columns = false;
}
scope.table_expression_node_to_data.emplace(table_expression_node, std::move(table_expression_data));
@ -4672,11 +4699,10 @@ void QueryAnalyzer::resolveTableFunction(QueryTreeNodePtr & table_function_node,
table_function_ptr->parseArguments(table_function_ast, scope_context);
uint64_t use_structure_from_insertion_table_in_table_functions = scope_context->getSettingsRef().use_structure_from_insertion_table_in_table_functions;
if (!nested_table_function &&
use_structure_from_insertion_table_in_table_functions &&
scope_context->hasInsertionTable() &&
table_function_ptr->needStructureHint())
uint64_t use_structure_from_insertion_table_in_table_functions
= scope_context->getSettingsRef()[Setting::use_structure_from_insertion_table_in_table_functions];
if (!nested_table_function && use_structure_from_insertion_table_in_table_functions && scope_context->hasInsertionTable()
&& table_function_ptr->needStructureHint())
{
const auto & insertion_table = scope_context->getInsertionTable();
if (!insertion_table.empty())
@ -4806,8 +4832,8 @@ void QueryAnalyzer::resolveTableFunction(QueryTreeNodePtr & table_function_node,
if (!structure_hint.empty())
table_function_ptr->setStructureHint(structure_hint);
} else if (use_structure_from_insertion_table_in_table_functions == 1)
}
else if (use_structure_from_insertion_table_in_table_functions == 1)
throw Exception(ErrorCodes::NUMBER_OF_COLUMNS_DOESNT_MATCH, "Number of columns in insert table less than required by SELECT expression.");
}
}
@ -4931,7 +4957,7 @@ void QueryAnalyzer::resolveArrayJoin(QueryTreeNodePtr & array_join_node, Identif
void QueryAnalyzer::checkDuplicateTableNamesOrAlias(const QueryTreeNodePtr & join_node, QueryTreeNodePtr & left_table_expr, QueryTreeNodePtr & right_table_expr, IdentifierResolveScope & scope)
{
Names column_names;
if (!scope.context->getSettingsRef().joined_subquery_requires_alias)
if (!scope.context->getSettingsRef()[Setting::joined_subquery_requires_alias])
return;
if (join_node->as<JoinNode &>().getKind() != JoinKind::Paste)
@ -5051,7 +5077,7 @@ void QueryAnalyzer::resolveJoin(QueryTreeNodePtr & join_node, IdentifierResolveS
* despite the fact that column from USING could be resolved from left table.
* It's compatibility with a default behavior for old analyzer.
*/
if (settings.analyzer_compatibility_join_using_top_level_identifier)
if (settings[Setting::analyzer_compatibility_join_using_top_level_identifier])
result_left_table_expression = try_resolve_identifier_from_query_projection(identifier_full_name, join_node_typed.getLeftTableExpression(), scope);
IdentifierLookup identifier_lookup{identifier_node->getIdentifier(), IdentifierLookupContext::EXPRESSION};
@ -5070,7 +5096,7 @@ void QueryAnalyzer::resolveJoin(QueryTreeNodePtr & join_node, IdentifierResolveS
{
String extra_message;
const QueryNode * query_node = scope.scope_node ? scope.scope_node->as<QueryNode>() : nullptr;
if (settings.analyzer_compatibility_join_using_top_level_identifier && query_node)
if (settings[Setting::analyzer_compatibility_join_using_top_level_identifier] && query_node)
{
for (const auto & projection_node : query_node->getProjection().getNodes())
{
@ -5250,11 +5276,9 @@ void QueryAnalyzer::resolveQueryJoinTreeNode(QueryTreeNodePtr & join_tree_node,
*/
void QueryAnalyzer::resolveQuery(const QueryTreeNodePtr & query_node, IdentifierResolveScope & scope)
{
size_t max_subquery_depth = scope.context->getSettingsRef().max_subquery_depth;
size_t max_subquery_depth = scope.context->getSettingsRef()[Setting::max_subquery_depth];
if (max_subquery_depth && scope.subquery_depth > max_subquery_depth)
throw Exception(ErrorCodes::TOO_DEEP_SUBQUERIES,
"Too deep subqueries. Maximum: {}",
max_subquery_depth);
throw Exception(ErrorCodes::TOO_DEEP_SUBQUERIES, "Too deep subqueries. Maximum: {}", max_subquery_depth);
auto & query_node_typed = query_node->as<QueryNode &>();
@ -5588,7 +5612,7 @@ void QueryAnalyzer::resolveQuery(const QueryTreeNodePtr & query_node, Identifier
expandGroupByAll(query_node_typed);
validateFilters(query_node);
validateAggregates(query_node, { .group_by_use_nulls = scope.group_by_use_nulls });
validateAggregates(query_node, {.group_by_use_nulls = scope.group_by_use_nulls});
for (const auto & column : projection_columns)
{

View File

@ -14,6 +14,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsSeconds lock_acquire_timeout;
}
TableNode::TableNode(StoragePtr storage_, StorageID storage_id_, TableLockHolder storage_lock_, StorageSnapshotPtr storage_snapshot_)
: IQueryTreeNode(children_size)
@ -29,9 +33,10 @@ TableNode::TableNode(StoragePtr storage_, TableLockHolder storage_lock_, Storage
}
TableNode::TableNode(StoragePtr storage_, const ContextPtr & context)
: TableNode(storage_,
storage_->lockForShare(context->getInitialQueryId(), context->getSettingsRef().lock_acquire_timeout),
storage_->getStorageSnapshot(storage_->getInMemoryMetadataPtr(), context))
: TableNode(
storage_,
storage_->lockForShare(context->getInitialQueryId(), context->getSettingsRef()[Setting::lock_acquire_timeout]),
storage_->getStorageSnapshot(storage_->getInMemoryMetadataPtr(), context))
{
}
@ -39,7 +44,7 @@ void TableNode::updateStorage(StoragePtr storage_value, const ContextPtr & conte
{
storage = std::move(storage_value);
storage_id = storage->getStorageID();
storage_lock = storage->lockForShare(context->getInitialQueryId(), context->getSettingsRef().lock_acquire_timeout);
storage_lock = storage->lockForShare(context->getInitialQueryId(), context->getSettingsRef()[Setting::lock_acquire_timeout]);
storage_snapshot = storage->getStorageSnapshot(storage->getInMemoryMetadataPtr(), context);
}

View File

@ -36,6 +36,12 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool extremes;
extern const SettingsUInt64 max_result_bytes;
extern const SettingsUInt64 max_result_rows;
}
namespace ErrorCodes
{
@ -868,10 +874,10 @@ void updateContextForSubqueryExecution(ContextMutablePtr & mutable_context)
* which are checked separately (in the Set, Join objects).
*/
Settings subquery_settings = mutable_context->getSettingsCopy();
subquery_settings.max_result_rows = 0;
subquery_settings.max_result_bytes = 0;
subquery_settings[Setting::max_result_rows] = 0;
subquery_settings[Setting::max_result_bytes] = 0;
/// The calculation of extremes does not make sense and is not necessary (if you do it, then the extremes of the subquery can be taken for whole query).
subquery_settings.extremes = false;
subquery_settings[Setting::extremes] = false;
mutable_context->setSettings(subquery_settings);
}

View File

@ -35,6 +35,13 @@ namespace ProfileEvents
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 backup_restore_keeper_retry_initial_backoff_ms;
extern const SettingsUInt64 backup_restore_keeper_retry_max_backoff_ms;
extern const SettingsUInt64 backup_restore_keeper_max_retries;
extern const SettingsSeconds lock_acquire_timeout;
}
namespace ErrorCodes
{
@ -105,9 +112,9 @@ BackupEntriesCollector::BackupEntriesCollector(
, compare_collected_metadata(context->getConfigRef().getBool("backups.compare_collected_metadata", true))
, log(getLogger("BackupEntriesCollector"))
, global_zookeeper_retries_info(
context->getSettingsRef().backup_restore_keeper_max_retries,
context->getSettingsRef().backup_restore_keeper_retry_initial_backoff_ms,
context->getSettingsRef().backup_restore_keeper_retry_max_backoff_ms)
context->getSettingsRef()[Setting::backup_restore_keeper_max_retries],
context->getSettingsRef()[Setting::backup_restore_keeper_retry_initial_backoff_ms],
context->getSettingsRef()[Setting::backup_restore_keeper_retry_max_backoff_ms])
, threadpool(threadpool_)
{
}
@ -653,7 +660,7 @@ void BackupEntriesCollector::lockTablesForReading()
checkIsQueryCancelled();
table_info.table_lock = storage->tryLockForShare(context->getInitialQueryId(), context->getSettingsRef().lock_acquire_timeout);
table_info.table_lock = storage->tryLockForShare(context->getInitialQueryId(), context->getSettingsRef()[Setting::lock_acquire_timeout]);
}
std::erase_if(

View File

@ -25,6 +25,16 @@ namespace fs = std::filesystem;
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 backup_restore_s3_retry_attempts;
extern const SettingsBool enable_s3_requests_logging;
extern const SettingsBool s3_disable_checksum;
extern const SettingsUInt64 s3_max_connections;
extern const SettingsUInt64 s3_max_redirects;
}
namespace ErrorCodes
{
extern const int S3_ERROR;
@ -55,16 +65,16 @@ namespace
S3::PocoHTTPClientConfiguration client_configuration = S3::ClientFactory::instance().createClientConfiguration(
settings.auth_settings.region,
context->getRemoteHostFilter(),
static_cast<unsigned>(local_settings.s3_max_redirects),
static_cast<unsigned>(local_settings.backup_restore_s3_retry_attempts),
local_settings.enable_s3_requests_logging,
static_cast<unsigned>(local_settings[Setting::s3_max_redirects]),
static_cast<unsigned>(local_settings[Setting::backup_restore_s3_retry_attempts]),
local_settings[Setting::enable_s3_requests_logging],
/* for_disk_s3 = */ false,
request_settings.get_request_throttler,
request_settings.put_request_throttler,
s3_uri.uri.getScheme());
client_configuration.endpointOverride = s3_uri.endpoint;
client_configuration.maxConnections = static_cast<unsigned>(global_settings.s3_max_connections);
client_configuration.maxConnections = static_cast<unsigned>(global_settings[Setting::s3_max_connections]);
/// Increase connect timeout
client_configuration.connectTimeoutMs = 10 * 1000;
/// Requests in backups can be extremely long, set to one hour
@ -74,7 +84,7 @@ namespace
S3::ClientSettings client_settings{
.use_virtual_addressing = s3_uri.is_virtual_hosted_style,
.disable_checksum = local_settings.s3_disable_checksum,
.disable_checksum = local_settings[Setting::s3_disable_checksum],
.gcs_issue_compose_request = context->getConfigRef().getBool("s3.gcs_issue_compose_request", false),
.is_s3express_bucket = S3::isS3ExpressEndpoint(s3_uri.endpoint),
};

View File

@ -43,6 +43,15 @@ namespace CurrentMetrics
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 backup_restore_batch_size_for_keeper_multiread;
extern const SettingsUInt64 backup_restore_keeper_max_retries;
extern const SettingsUInt64 backup_restore_keeper_retry_initial_backoff_ms;
extern const SettingsUInt64 backup_restore_keeper_retry_max_backoff_ms;
extern const SettingsUInt64 backup_restore_keeper_fault_injection_seed;
extern const SettingsFloat backup_restore_keeper_fault_injection_probability;
}
namespace ErrorCodes
{
@ -98,12 +107,12 @@ namespace
RestoreCoordinationRemote::RestoreKeeperSettings keeper_settings
{
.keeper_max_retries = context->getSettingsRef().backup_restore_keeper_max_retries,
.keeper_retry_initial_backoff_ms = context->getSettingsRef().backup_restore_keeper_retry_initial_backoff_ms,
.keeper_retry_max_backoff_ms = context->getSettingsRef().backup_restore_keeper_retry_max_backoff_ms,
.batch_size_for_keeper_multiread = context->getSettingsRef().backup_restore_batch_size_for_keeper_multiread,
.keeper_fault_injection_probability = context->getSettingsRef().backup_restore_keeper_fault_injection_probability,
.keeper_fault_injection_seed = context->getSettingsRef().backup_restore_keeper_fault_injection_seed
.keeper_max_retries = context->getSettingsRef()[Setting::backup_restore_keeper_max_retries],
.keeper_retry_initial_backoff_ms = context->getSettingsRef()[Setting::backup_restore_keeper_retry_initial_backoff_ms],
.keeper_retry_max_backoff_ms = context->getSettingsRef()[Setting::backup_restore_keeper_retry_max_backoff_ms],
.batch_size_for_keeper_multiread = context->getSettingsRef()[Setting::backup_restore_batch_size_for_keeper_multiread],
.keeper_fault_injection_probability = context->getSettingsRef()[Setting::backup_restore_keeper_fault_injection_probability],
.keeper_fault_injection_seed = context->getSettingsRef()[Setting::backup_restore_keeper_fault_injection_seed]
};
auto all_hosts = BackupSettings::Util::filterHostIDs(

View File

@ -36,6 +36,11 @@ namespace fs = std::filesystem;
namespace DB
{
namespace Setting
{
extern const SettingsSeconds lock_acquire_timeout;
}
namespace ErrorCodes
{
extern const int BACKUP_ENTRY_NOT_FOUND;
@ -949,7 +954,7 @@ void RestorerFromBackup::checkTable(const QualifiedTableName & table_name)
StoragePtr storage = database->getTable(resolved_id.table_name, context);
table_info.storage = storage;
table_info.table_lock = storage->lockForShare(context->getInitialQueryId(), context->getSettingsRef().lock_acquire_timeout);
table_info.table_lock = storage->lockForShare(context->getInitialQueryId(), context->getSettingsRef()[Setting::lock_acquire_timeout]);
if (!restore_settings.allow_different_table_def && !table_info.is_predefined_table)
{

View File

@ -5,20 +5,30 @@
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 backup_restore_keeper_max_retries;
extern const SettingsUInt64 backup_restore_keeper_retry_initial_backoff_ms;
extern const SettingsUInt64 backup_restore_keeper_retry_max_backoff_ms;
extern const SettingsUInt64 backup_restore_batch_size_for_keeper_multiread;
extern const SettingsFloat backup_restore_keeper_fault_injection_probability;
extern const SettingsUInt64 backup_restore_keeper_fault_injection_seed;
extern const SettingsUInt64 backup_restore_keeper_value_max_size;
extern const SettingsUInt64 backup_restore_batch_size_for_keeper_multi;
}
WithRetries::KeeperSettings WithRetries::KeeperSettings::fromContext(ContextPtr context)
{
return
{
.keeper_max_retries = context->getSettingsRef().backup_restore_keeper_max_retries,
.keeper_retry_initial_backoff_ms = context->getSettingsRef().backup_restore_keeper_retry_initial_backoff_ms,
.keeper_retry_max_backoff_ms = context->getSettingsRef().backup_restore_keeper_retry_max_backoff_ms,
.batch_size_for_keeper_multiread = context->getSettingsRef().backup_restore_batch_size_for_keeper_multiread,
.keeper_fault_injection_probability = context->getSettingsRef().backup_restore_keeper_fault_injection_probability,
.keeper_fault_injection_seed = context->getSettingsRef().backup_restore_keeper_fault_injection_seed,
.keeper_value_max_size = context->getSettingsRef().backup_restore_keeper_value_max_size,
.batch_size_for_keeper_multi = context->getSettingsRef().backup_restore_batch_size_for_keeper_multi,
.keeper_max_retries = context->getSettingsRef()[Setting::backup_restore_keeper_max_retries],
.keeper_retry_initial_backoff_ms = context->getSettingsRef()[Setting::backup_restore_keeper_retry_initial_backoff_ms],
.keeper_retry_max_backoff_ms = context->getSettingsRef()[Setting::backup_restore_keeper_retry_max_backoff_ms],
.batch_size_for_keeper_multiread = context->getSettingsRef()[Setting::backup_restore_batch_size_for_keeper_multiread],
.keeper_fault_injection_probability = context->getSettingsRef()[Setting::backup_restore_keeper_fault_injection_probability],
.keeper_fault_injection_seed = context->getSettingsRef()[Setting::backup_restore_keeper_fault_injection_seed],
.keeper_value_max_size = context->getSettingsRef()[Setting::backup_restore_keeper_value_max_size],
.batch_size_for_keeper_multi = context->getSettingsRef()[Setting::backup_restore_batch_size_for_keeper_multi],
};
}

View File

@ -10,6 +10,8 @@
namespace DB
{
struct ColumnWithTypeAndName;
using ColumnsWithTypeAndName = std::vector<ColumnWithTypeAndName>;
class CatBoostLibraryBridgeHelper final : public LibraryBridgeHelper
{

View File

@ -1,11 +1,12 @@
#pragma once
#include <Interpreters/Context.h>
#include <Poco/Logger.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <Poco/Net/HTTPRequest.h>
#include <Common/ShellCommand.h>
#include <Poco/Logger.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/URI.h>
#include <Poco/Util/AbstractConfiguration.h>
namespace DB
{

View File

@ -6,12 +6,16 @@
namespace DB
{
namespace Setting
{
extern const SettingsSeconds http_receive_timeout;
}
LibraryBridgeHelper::LibraryBridgeHelper(ContextPtr context_)
: IBridgeHelper(context_)
, config(context_->getConfigRef())
, log(getLogger("LibraryBridgeHelper"))
, http_timeout(context_->getGlobalContext()->getSettingsRef().http_receive_timeout.value)
, http_timeout(context_->getGlobalContext()->getSettingsRef()[Setting::http_receive_timeout].value)
, bridge_host(config.getString("library_bridge.host", DEFAULT_HOST))
, bridge_port(config.getUInt("library_bridge.port", DEFAULT_PORT))
, http_timeouts(ConnectionTimeouts::getHTTPTimeouts(context_->getSettingsRef(), context_->getServerSettings().keep_alive_timeout))

View File

@ -2,7 +2,6 @@
#include <base/argsToConfig.h>
#include <base/safeExit.h>
#include <Core/BaseSettingsProgramOptions.h>
#include <Common/clearPasswordFromCommandLine.h>
#include <Common/TerminalSize.h>
#include <Common/Exception.h>
@ -172,7 +171,8 @@ void ClientApplicationBase::init(int argc, char ** argv)
("stage", po::value<std::string>()->default_value("complete"), "Request query processing up to specified stage: complete,fetch_columns,with_mergeable_state,with_mergeable_state_after_aggregation,with_mergeable_state_after_aggregation_and_limit")
("progress", po::value<ProgressOption>()->implicit_value(ProgressOption::TTY, "tty")->default_value(ProgressOption::DEFAULT, "default"), "Print progress of queries execution - to TTY: tty|on|1|true|yes; to STDERR non-interactive mode: err; OFF: off|0|false|no; DEFAULT - interactive to TTY, non-interactive is off")
("progress-table", po::value<ProgressOption>()->implicit_value(ProgressOption::TTY, "tty")->default_value(ProgressOption::DEFAULT, "default"), "Print progress table with main metrics of queries execution - to TTY: tty|on|1|true|yes; to STDERR non-interactive mode: err; OFF: off|0|false|no; DEFAULT - interactive to TTY, non-interactive is off")
("enable-progress-table-toggle", po::value<bool>()->default_value(true), "Enable toggling of the progress table by pressing the control key (Space). This is applicable in interactive mode.")
("disable_suggestion,A", "Disable loading suggestion data. Note that suggestion data is loaded asynchronously through a second connection to ClickHouse server. Also it is reasonable to disable suggestion if you want to paste a query with TAB characters. Shorthand option -A is for those who get used to mysql client.")
("wait_for_suggestions_to_load", "Load suggestion data synchonously.")
("time,t", "print query execution time to stderr in non-interactive mode (for benchmarks)")
@ -317,6 +317,26 @@ void ClientApplicationBase::init(int argc, char ** argv)
break;
}
}
if (options.count("progress-table"))
{
switch (options["progress-table"].as<ProgressOption>())
{
case DEFAULT:
config().setString("progress-table", "default");
break;
case OFF:
config().setString("progress-table", "off");
break;
case TTY:
config().setString("progress-table", "tty");
break;
case ERR:
config().setString("progress-table", "err");
break;
}
}
if (options.count("enable-progress-table-toggle"))
getClientConfiguration().setBool("enable-progress-table-toggle", options["enable-progress-table-toggle"].as<bool>());
if (options.count("echo"))
getClientConfiguration().setBool("echo", true);
if (options.count("disable_suggestion"))

View File

@ -7,7 +7,6 @@
#include <base/safeExit.h>
#include <Core/Block.h>
#include <Core/BaseSettingsProgramOptions.h>
#include <Core/Protocol.h>
#include <Common/DateLUT.h>
#include <Common/MemoryTracker.h>
@ -15,6 +14,7 @@
#include <Common/Exception.h>
#include <Common/getNumberOfPhysicalCPUCores.h>
#include <Common/typeid_cast.h>
#include <Common/KeystrokeInterceptor.h>
#include <Common/TerminalSize.h>
#include <Common/StringUtils.h>
#include <Common/filesystemHelpers.h>
@ -93,6 +93,21 @@ using namespace std::literals;
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_settings_after_format_in_insert;
extern const SettingsBool async_insert;
extern const SettingsDialect dialect;
extern const SettingsUInt64 max_block_size;
extern const SettingsUInt64 max_insert_block_size;
extern const SettingsUInt64 max_parser_backtracks;
extern const SettingsUInt64 max_parser_depth;
extern const SettingsUInt64 max_query_size;
extern const SettingsUInt64 output_format_pretty_max_rows;
extern const SettingsUInt64 output_format_pretty_max_value_width;
extern const SettingsBool partial_result_on_first_cancel;
extern const SettingsBool throw_if_no_data_to_insert;
}
namespace ErrorCodes
{
@ -274,6 +289,7 @@ ClientBase::ClientBase(
: std_in(in_fd_)
, std_out(out_fd_)
, progress_indication(output_stream_, in_fd_, err_fd_)
, progress_table(output_stream_, in_fd_, err_fd_)
, in_fd(in_fd_)
, out_fd(out_fd_)
, err_fd(err_fd_)
@ -295,24 +311,24 @@ ASTPtr ClientBase::parseQuery(const char *& pos, const char * end, const Setting
size_t max_length = 0;
if (!allow_multi_statements)
max_length = settings.max_query_size;
max_length = settings[Setting::max_query_size];
const Dialect & dialect = settings.dialect;
const Dialect dialect = settings[Setting::dialect];
if (dialect == Dialect::kusto)
parser = std::make_unique<ParserKQLStatement>(end, settings.allow_settings_after_format_in_insert);
parser = std::make_unique<ParserKQLStatement>(end, settings[Setting::allow_settings_after_format_in_insert]);
else if (dialect == Dialect::prql)
parser = std::make_unique<ParserPRQLQuery>(max_length, settings.max_parser_depth, settings.max_parser_backtracks);
parser = std::make_unique<ParserPRQLQuery>(max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks]);
else
parser = std::make_unique<ParserQuery>(end, settings.allow_settings_after_format_in_insert);
parser = std::make_unique<ParserQuery>(end, settings[Setting::allow_settings_after_format_in_insert]);
if (is_interactive || ignore_error)
{
String message;
if (dialect == Dialect::kusto)
res = tryParseKQLQuery(*parser, pos, end, message, true, "", allow_multi_statements, max_length, settings.max_parser_depth, settings.max_parser_backtracks, true);
res = tryParseKQLQuery(*parser, pos, end, message, true, "", allow_multi_statements, max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks], true);
else
res = tryParseQuery(*parser, pos, end, message, true, "", allow_multi_statements, max_length, settings.max_parser_depth, settings.max_parser_backtracks, true);
res = tryParseQuery(*parser, pos, end, message, true, "", allow_multi_statements, max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks], true);
if (!res)
{
@ -323,9 +339,9 @@ ASTPtr ClientBase::parseQuery(const char *& pos, const char * end, const Setting
else
{
if (dialect == Dialect::kusto)
res = parseKQLQueryAndMovePosition(*parser, pos, end, "", allow_multi_statements, max_length, settings.max_parser_depth, settings.max_parser_backtracks);
res = parseKQLQueryAndMovePosition(*parser, pos, end, "", allow_multi_statements, max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks]);
else
res = parseQueryAndMovePosition(*parser, pos, end, "", allow_multi_statements, max_length, settings.max_parser_depth, settings.max_parser_backtracks);
res = parseQueryAndMovePosition(*parser, pos, end, "", allow_multi_statements, max_length, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks]);
}
if (is_interactive)
@ -346,7 +362,8 @@ ASTPtr ClientBase::parseQuery(const char *& pos, const char * end, const Setting
/// Consumes trailing semicolons and tries to consume the same-line trailing comment.
void ClientBase::adjustQueryEnd(const char *& this_query_end, const char * all_queries_end, uint32_t max_parser_depth, uint32_t max_parser_backtracks)
void ClientBase::adjustQueryEnd(
const char *& this_query_end, const char * all_queries_end, uint32_t max_parser_depth, uint32_t max_parser_backtracks)
{
// We have to skip the trailing semicolon that might be left
// after VALUES parsing or just after a normal semicolon-terminated query.
@ -423,6 +440,8 @@ void ClientBase::onData(Block & block, ASTPtr parsed_query)
/// If results are written INTO OUTFILE, we can avoid clearing progress to avoid flicker.
if (need_render_progress && tty_buf && (!select_into_file || select_into_file_and_stdout))
progress_indication.clearProgressOutput(*tty_buf);
if (need_render_progress_table && tty_buf && (!select_into_file || select_into_file_and_stdout))
progress_table.clearTableOutput(*tty_buf);
try
{
@ -438,13 +457,20 @@ void ClientBase::onData(Block & block, ASTPtr parsed_query)
/// Received data block is immediately displayed to the user.
output_format->flush();
/// Restore progress bar after data block.
/// Restore progress bar and progress table after data block.
if (need_render_progress && tty_buf)
{
if (select_into_file && !select_into_file_and_stdout)
error_stream << "\r";
progress_indication.writeProgress(*tty_buf);
}
if (need_render_progress_table && tty_buf)
{
if (!need_render_progress && select_into_file && !select_into_file_and_stdout)
error_stream << "\r";
bool toggle_enabled = getClientConfiguration().getBool("enable-progress-table-toggle", true);
progress_table.writeTable(*tty_buf, show_progress_table.load(), toggle_enabled);
}
}
@ -453,6 +479,8 @@ void ClientBase::onLogData(Block & block)
initLogsOutputStream();
if (need_render_progress && tty_buf)
progress_indication.clearProgressOutput(*tty_buf);
if (need_render_progress_table && tty_buf)
progress_table.clearTableOutput(*tty_buf);
logs_out_stream->writeLogs(block);
logs_out_stream->flush();
}
@ -672,16 +700,16 @@ void ClientBase::adjustSettings()
/// Do not limit pretty format output in case of --pager specified or in case of stdout is not a tty.
if (!pager.empty() || !stdout_is_a_tty)
{
if (!global_context->getSettingsRef().output_format_pretty_max_rows.changed)
if (!global_context->getSettingsRef()[Setting::output_format_pretty_max_rows].changed)
{
settings.output_format_pretty_max_rows = std::numeric_limits<UInt64>::max();
settings.output_format_pretty_max_rows.changed = false;
settings[Setting::output_format_pretty_max_rows] = std::numeric_limits<UInt64>::max();
settings[Setting::output_format_pretty_max_rows].changed = false;
}
if (!global_context->getSettingsRef().output_format_pretty_max_value_width.changed)
if (!global_context->getSettingsRef()[Setting::output_format_pretty_max_value_width].changed)
{
settings.output_format_pretty_max_value_width = std::numeric_limits<UInt64>::max();
settings.output_format_pretty_max_value_width.changed = false;
settings[Setting::output_format_pretty_max_value_width] = std::numeric_limits<UInt64>::max();
settings[Setting::output_format_pretty_max_value_width].changed = false;
}
}
@ -767,31 +795,37 @@ void ClientBase::setDefaultFormatsAndCompressionFromConfiguration()
default_input_format = "TSV";
}
format_max_block_size = getClientConfiguration().getUInt64("format_max_block_size",
global_context->getSettingsRef().max_block_size);
format_max_block_size = getClientConfiguration().getUInt64("format_max_block_size", global_context->getSettingsRef()[Setting::max_block_size]);
/// Setting value from cmd arg overrides one from config
if (global_context->getSettingsRef().max_insert_block_size.changed)
if (global_context->getSettingsRef()[Setting::max_insert_block_size].changed)
{
insert_format_max_block_size = global_context->getSettingsRef().max_insert_block_size;
insert_format_max_block_size = global_context->getSettingsRef()[Setting::max_insert_block_size];
}
else
{
insert_format_max_block_size = getClientConfiguration().getUInt64("insert_format_max_block_size",
global_context->getSettingsRef().max_insert_block_size);
insert_format_max_block_size
= getClientConfiguration().getUInt64("insert_format_max_block_size", global_context->getSettingsRef()[Setting::max_insert_block_size]);
}
}
void ClientBase::initTTYBuffer(ProgressOption progress)
void ClientBase::initTTYBuffer(ProgressOption progress_option, ProgressOption progress_table_option)
{
if (tty_buf)
return;
if (progress == ProgressOption::OFF || (!is_interactive && progress == ProgressOption::DEFAULT))
{
need_render_progress = false;
return;
}
if (progress_option == ProgressOption::OFF || (!is_interactive && progress_option == ProgressOption::DEFAULT))
need_render_progress = false;
if (progress_table_option == ProgressOption::OFF || (!is_interactive && progress_table_option == ProgressOption::DEFAULT))
need_render_progress_table = false;
if (!need_render_progress && !need_render_progress_table)
return;
/// If need_render_progress and need_render_progress_table are enabled,
/// use ProgressOption that was set for the progress bar for progress table as well.
ProgressOption progress = progress_option ? progress_option : progress_table_option;
static constexpr auto tty_file_name = "/dev/tty";
@ -837,7 +871,20 @@ void ClientBase::initTTYBuffer(ProgressOption progress)
tty_buf = std::make_unique<WriteBufferFromFileDescriptor>(STDERR_FILENO, buf_size);
}
else
{
need_render_progress = false;
need_render_progress_table = false;
}
}
void ClientBase::initKeystrokeInterceptor()
{
if (is_interactive && need_render_progress_table && getClientConfiguration().getBool("enable-progress-table-toggle", true))
{
keystroke_interceptor = std::make_unique<KeystrokeInterceptor>(in_fd);
keystroke_interceptor->registerCallback(' ', [this]() { show_progress_table = !show_progress_table; });
}
}
void ClientBase::updateSuggest(const ASTPtr & ast)
@ -878,7 +925,7 @@ bool ClientBase::isSyncInsertWithData(const ASTInsertQuery & insert_query, const
if (insert_query.settings_ast)
settings.applyChanges(insert_query.settings_ast->as<ASTSetQuery>()->changes);
return !settings.async_insert;
return !settings[Setting::async_insert];
}
void ClientBase::processTextAsSingleQuery(const String & full_query)
@ -1031,7 +1078,7 @@ void ClientBase::processOrdinaryQuery(const String & query_to_execute, ASTPtr pa
}
const auto & settings = client_context->getSettingsRef();
const Int32 signals_before_stop = settings.partial_result_on_first_cancel ? 2 : 1;
const Int32 signals_before_stop = settings[Setting::partial_result_on_first_cancel] ? 2 : 1;
int retries_left = 10;
while (retries_left)
@ -1059,11 +1106,11 @@ void ClientBase::processOrdinaryQuery(const String & query_to_execute, ASTPtr pa
catch (const NetException &)
{
// We still want to attempt to process whatever we already received or can receive (socket receive buffer can be not empty)
receiveResult(parsed_query, signals_before_stop, settings.partial_result_on_first_cancel);
receiveResult(parsed_query, signals_before_stop, settings[Setting::partial_result_on_first_cancel]);
throw;
}
receiveResult(parsed_query, signals_before_stop, settings.partial_result_on_first_cancel);
receiveResult(parsed_query, signals_before_stop, settings[Setting::partial_result_on_first_cancel]);
break;
}
@ -1101,6 +1148,9 @@ void ClientBase::receiveResult(ASTPtr parsed_query, Int32 signals_before_stop, b
std::exception_ptr local_format_error;
if (keystroke_interceptor)
keystroke_interceptor->startIntercept();
while (true)
{
Stopwatch receive_watch(CLOCK_MONOTONIC_COARSE);
@ -1155,8 +1205,17 @@ void ClientBase::receiveResult(ASTPtr parsed_query, Int32 signals_before_stop, b
local_format_error = std::current_exception();
connection->sendCancel();
}
catch (...)
{
if (keystroke_interceptor)
keystroke_interceptor->stopIntercept();
throw;
}
}
if (keystroke_interceptor)
keystroke_interceptor->stopIntercept();
if (local_format_error)
std::rethrow_exception(local_format_error);
@ -1252,6 +1311,8 @@ void ClientBase::onEndOfStream()
{
if (need_render_progress && tty_buf)
progress_indication.clearProgressOutput(*tty_buf);
if (need_render_progress_table && tty_buf)
progress_table.clearTableOutput(*tty_buf);
if (output_format)
{
@ -1330,9 +1391,15 @@ void ClientBase::onProfileEvents(Block & block)
thread_times[host_name].peak_memory_usage = value;
}
progress_indication.updateThreadEventData(thread_times);
progress_table.updateTable(block);
if (need_render_progress && tty_buf)
progress_indication.writeProgress(*tty_buf);
if (need_render_progress_table && tty_buf)
{
bool toggle_enabled = getClientConfiguration().getBool("enable-progress-table-toggle", true);
progress_table.writeTable(*tty_buf, show_progress_table.load(), toggle_enabled);
}
if (profile_events.print)
{
@ -1343,6 +1410,8 @@ void ClientBase::onProfileEvents(Block & block)
initLogsOutputStream();
if (need_render_progress && tty_buf)
progress_indication.clearProgressOutput(*tty_buf);
if (need_render_progress_table && tty_buf)
progress_table.clearTableOutput(*tty_buf);
logs_out_stream->writeProfileEvents(block);
logs_out_stream->flush();
@ -1491,7 +1560,7 @@ void ClientBase::processInsertQuery(const String & query_to_execute, ASTPtr pars
if ((!parsed_insert_query.data && !parsed_insert_query.infile) && (is_interactive || (!stdin_is_a_tty && !isStdinNotEmptyAndValid(std_in))))
{
const auto & settings = client_context->getSettingsRef();
if (settings.throw_if_no_data_to_insert)
if (settings[Setting::throw_if_no_data_to_insert])
throw Exception(ErrorCodes::NO_DATA_TO_INSERT, "No data to insert");
else
return;
@ -1609,14 +1678,14 @@ void ClientBase::sendData(Block & sample, const ColumnsDescription & columns_des
auto metadata = storage->getInMemoryMetadataPtr();
QueryPlan plan;
storage->read(
plan,
sample.getNames(),
storage->getStorageSnapshot(metadata, client_context),
query_info,
client_context,
{},
client_context->getSettingsRef().max_block_size,
getNumberOfPhysicalCPUCores());
plan,
sample.getNames(),
storage->getStorageSnapshot(metadata, client_context),
query_info,
client_context,
{},
client_context->getSettingsRef()[Setting::max_block_size],
getNumberOfPhysicalCPUCores());
auto builder = plan.buildQueryPipeline(
QueryPlanOptimizationSettings::fromContext(client_context),
@ -1824,6 +1893,8 @@ void ClientBase::cancelQuery()
connection->sendCancel();
if (need_render_progress && tty_buf)
progress_indication.clearProgressOutput(*tty_buf);
if (need_render_progress_table && tty_buf)
progress_table.clearTableOutput(*tty_buf);
if (is_interactive)
output_stream << "Cancelling query." << std::endl;
@ -1890,6 +1961,7 @@ void ClientBase::processParsedSingleQuery(const String & full_query, const Strin
processed_rows = 0;
written_first_block = false;
progress_indication.resetProgress();
progress_table.resetTable();
profile_events.watch.restart();
{
@ -1953,7 +2025,7 @@ void ClientBase::processParsedSingleQuery(const String & full_query, const Strin
if (insert && insert->select)
insert->tryFindInputFunction(input_function);
bool is_async_insert_with_inlined_data = client_context->getSettingsRef().async_insert && insert && insert->hasInlinedData();
bool is_async_insert_with_inlined_data = client_context->getSettingsRef()[Setting::async_insert] && insert && insert->hasInlinedData();
if (is_async_insert_with_inlined_data)
{
@ -2016,6 +2088,8 @@ void ClientBase::processParsedSingleQuery(const String & full_query, const Strin
initLogsOutputStream();
if (need_render_progress && tty_buf)
progress_indication.clearProgressOutput(*tty_buf);
if (need_render_progress_table && tty_buf)
progress_table.clearTableOutput(*tty_buf);
logs_out_stream->writeProfileEvents(profile_events.last_block);
logs_out_stream->flush();
@ -2029,6 +2103,8 @@ void ClientBase::processParsedSingleQuery(const String & full_query, const Strin
output_stream << processed_rows << " row" << (processed_rows == 1 ? "" : "s") << " in set. ";
output_stream << "Elapsed: " << progress_indication.elapsedSeconds() << " sec. ";
progress_indication.writeFinalProgress();
if (need_render_progress_table && show_progress_table)
progress_table.writeFinalTable();
output_stream << std::endl << std::endl;
}
else
@ -2038,11 +2114,11 @@ void ClientBase::processParsedSingleQuery(const String & full_query, const Strin
error_stream << progress_indication.elapsedSeconds() << "\n";
const auto & print_memory_mode = config.getString("print-memory-to-stderr", "");
auto peak_memeory_usage = std::max<Int64>(progress_indication.getMemoryUsage().peak, 0);
auto peak_memory_usage = std::max<Int64>(progress_indication.getMemoryUsage().peak, 0);
if (print_memory_mode == "default")
error_stream << peak_memeory_usage << "\n";
error_stream << peak_memory_usage << "\n";
else if (print_memory_mode == "readable")
error_stream << formatReadableSizeWithBinarySuffix(peak_memeory_usage) << "\n";
error_stream << formatReadableSizeWithBinarySuffix(peak_memory_usage) << "\n";
}
if (!is_interactive && getClientConfiguration().getBool("print-num-processed-rows", false))
@ -2075,8 +2151,8 @@ MultiQueryProcessingStage ClientBase::analyzeMultiQueryText(
if (this_query_begin >= all_queries_end)
return MultiQueryProcessingStage::QUERIES_END;
unsigned max_parser_depth = static_cast<unsigned>(client_context->getSettingsRef().max_parser_depth);
unsigned max_parser_backtracks = static_cast<unsigned>(client_context->getSettingsRef().max_parser_backtracks);
unsigned max_parser_depth = static_cast<unsigned>(client_context->getSettingsRef()[Setting::max_parser_depth]);
unsigned max_parser_backtracks = static_cast<unsigned>(client_context->getSettingsRef()[Setting::max_parser_backtracks]);
// If there are only comments left until the end of file, we just
// stop. The parser can't handle this situation because it always
@ -2400,9 +2476,10 @@ bool ClientBase::executeMultiQuery(const String & all_queries_text)
{
this_query_end = insert_ast->end;
adjustQueryEnd(
this_query_end, all_queries_end,
static_cast<unsigned>(client_context->getSettingsRef().max_parser_depth),
static_cast<unsigned>(client_context->getSettingsRef().max_parser_backtracks));
this_query_end,
all_queries_end,
static_cast<unsigned>(client_context->getSettingsRef()[Setting::max_parser_depth]),
static_cast<unsigned>(client_context->getSettingsRef()[Setting::max_parser_backtracks]));
}
// Report error.

View File

@ -6,6 +6,7 @@
#include <Common/DNSResolver.h>
#include <Common/InterruptListener.h>
#include <Common/ProgressIndication.h>
#include <Common/ProgressTable.h>
#include <Common/ShellCommand.h>
#include <Common/Stopwatch.h>
#include <Core/ExternalTable.h>
@ -68,6 +69,7 @@ ProgressOption toProgressOption(std::string progress);
std::istream& operator>> (std::istream & in, ProgressOption & progress);
class InternalTextLogs;
class KeystrokeInterceptor;
class WriteBufferFromFileDescriptor;
/**
@ -245,7 +247,8 @@ protected:
void setDefaultFormatsAndCompressionFromConfiguration();
void initTTYBuffer(ProgressOption progress);
void initTTYBuffer(ProgressOption progress_option, ProgressOption progress_table_option);
void initKeystrokeInterceptor();
/// Should be one of the first, to be destroyed the last,
/// since other members can use them.
@ -255,6 +258,8 @@ protected:
/// Client context is a context used only by the client to parse queries, process query parameters and to connect to clickhouse-server.
ContextMutablePtr client_context;
std::unique_ptr<KeystrokeInterceptor> keystroke_interceptor;
bool is_interactive = false; /// Use either interactive line editing interface or batch mode.
bool delayed_interactive = false;
@ -332,7 +337,10 @@ protected:
String server_display_name;
ProgressIndication progress_indication;
ProgressTable progress_table;
bool need_render_progress = true;
bool need_render_progress_table = true;
std::atomic_bool show_progress_table = false;
bool need_render_profile_events = true;
bool written_first_block = false;
size_t processed_rows = 0; /// How many rows have been read or written.

View File

@ -83,9 +83,9 @@ private:
void ClientApplicationBase::parseAndCheckOptions(OptionsDescription & options_description, po::variables_map & options, Arguments & arguments)
{
if (allow_repeated_settings)
addProgramOptionsAsMultitokens(cmd_settings, options_description.main_description.value());
cmd_settings.addToProgramOptionsAsMultitokens(options_description.main_description.value());
else
addProgramOptions(cmd_settings, options_description.main_description.value());
cmd_settings.addToProgramOptions(options_description.main_description.value());
if (allow_merge_tree_settings)
{

View File

@ -51,6 +51,15 @@ namespace CurrentMetrics
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_experimental_codecs;
extern const SettingsBool allow_suspicious_codecs;
extern const SettingsBool enable_deflate_qpl_codec;
extern const SettingsBool enable_zstd_qat_codec;
extern const SettingsString network_compression_method;
extern const SettingsInt64 network_zstd_compression_level;
}
namespace FailPoints
{
@ -791,19 +800,19 @@ void Connection::sendQuery(
if (settings)
{
std::optional<int> level;
std::string method = Poco::toUpper(settings->network_compression_method.toString());
std::string method = Poco::toUpper((*settings)[Setting::network_compression_method].toString());
/// Bad custom logic
if (method == "ZSTD")
level = settings->network_zstd_compression_level;
level = (*settings)[Setting::network_zstd_compression_level];
CompressionCodecFactory::instance().validateCodec(
method,
level,
!settings->allow_suspicious_codecs,
settings->allow_experimental_codecs,
settings->enable_deflate_qpl_codec,
settings->enable_zstd_qat_codec);
!(*settings)[Setting::allow_suspicious_codecs],
(*settings)[Setting::allow_experimental_codecs],
(*settings)[Setting::enable_deflate_qpl_codec],
(*settings)[Setting::enable_zstd_qat_codec]);
compression_codec = CompressionCodecFactory::instance().get(method, level);
}
else

View File

@ -14,6 +14,10 @@ namespace ProfileEvents
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 max_replica_delay_for_distributed_queries;
}
namespace ErrorCodes
{
@ -78,7 +82,7 @@ void ConnectionEstablisher::run(ConnectionEstablisher::TryResult & result, std::
LOG_TRACE(log, "Table {}.{} is readonly on server {}", table_to_check->database, table_to_check->table, result.entry->getDescription());
}
const UInt64 max_allowed_delay = settings.max_replica_delay_for_distributed_queries;
const UInt64 max_allowed_delay = settings[Setting::max_replica_delay_for_distributed_queries];
if (!max_allowed_delay)
{
result.is_up_to_date = true;

View File

@ -5,6 +5,10 @@
namespace DB
{
namespace Setting
{
extern const SettingsMilliseconds connection_pool_max_wait_ms;
}
ConnectionPoolPtr ConnectionPoolFactory::get(
unsigned max_connections,
@ -93,7 +97,7 @@ ConnectionPoolFactory & ConnectionPoolFactory::instance()
IConnectionPool::Entry ConnectionPool::get(const DB::ConnectionTimeouts& timeouts, const DB::Settings& settings,
bool force_connected)
{
Entry entry = Base::get(settings.connection_pool_max_wait_ms.totalMilliseconds());
Entry entry = Base::get(settings[Setting::connection_pool_max_wait_ms].totalMilliseconds());
if (force_connected)
entry->forceConnected(timeouts);

View File

@ -16,6 +16,17 @@
namespace DB
{
namespace Setting
{
extern const SettingsUInt64 connections_with_failover_max_tries;
extern const SettingsBool distributed_insert_skip_read_only_replicas;
extern const SettingsUInt64 distributed_replica_max_ignored_errors;
extern const SettingsBool fallback_to_stale_replicas_for_distributed_queries;
extern const SettingsLoadBalancing load_balancing;
extern const SettingsUInt64 load_balancing_first_offset;
extern const SettingsNonZeroUInt64 max_parallel_replicas;
extern const SettingsBool skip_unavailable_shards;
}
namespace ErrorCodes
{
@ -47,10 +58,10 @@ ConnectionPoolWithFailover::ConnectionPoolWithFailover(
IConnectionPool::Entry ConnectionPoolWithFailover::get(const ConnectionTimeouts & timeouts)
{
Settings settings;
settings.load_balancing = get_priority_load_balancing.load_balancing;
settings.load_balancing_first_offset = 0;
settings.distributed_replica_max_ignored_errors = 0;
settings.fallback_to_stale_replicas_for_distributed_queries = true;
settings[Setting::load_balancing] = get_priority_load_balancing.load_balancing;
settings[Setting::load_balancing_first_offset] = 0;
settings[Setting::distributed_replica_max_ignored_errors] = 0;
settings[Setting::fallback_to_stale_replicas_for_distributed_queries] = true;
return get(timeouts, settings, /* force_connected= */ true);
}
@ -68,13 +79,12 @@ IConnectionPool::Entry ConnectionPoolWithFailover::get(const ConnectionTimeouts
return tryGetEntry(pool, timeouts, fail_message, settings);
};
const size_t offset = settings.load_balancing_first_offset % nested_pools.size();
const LoadBalancing load_balancing = settings.load_balancing;
const size_t offset = settings[Setting::load_balancing_first_offset] % nested_pools.size();
GetPriorityFunc get_priority = get_priority_load_balancing.getPriorityFunc(load_balancing, offset, nested_pools.size());
GetPriorityFunc get_priority = get_priority_load_balancing.getPriorityFunc(settings[Setting::load_balancing], offset, nested_pools.size());
const UInt64 max_ignored_errors = settings.distributed_replica_max_ignored_errors;
const bool fallback_to_stale_replicas = settings.fallback_to_stale_replicas_for_distributed_queries;
const UInt64 max_ignored_errors = settings[Setting::distributed_replica_max_ignored_errors];
const bool fallback_to_stale_replicas = settings[Setting::fallback_to_stale_replicas_for_distributed_queries];
return Base::get(max_ignored_errors, fallback_to_stale_replicas, try_get_entry, get_priority);
}
@ -170,15 +180,13 @@ std::vector<ConnectionPoolWithFailover::TryResult> ConnectionPoolWithFailover::g
return getManyImpl(settings, pool_mode, try_get_entry,
/*skip_unavailable_endpoints=*/ false, /// skip_unavailable_endpoints is used to get the min number of entries, and we need at least one
/*priority_func=*/ {},
settings.distributed_insert_skip_read_only_replicas);
settings[Setting::distributed_insert_skip_read_only_replicas]);
}
ConnectionPoolWithFailover::Base::GetPriorityFunc ConnectionPoolWithFailover::makeGetPriorityFunc(const Settings & settings)
{
const size_t offset = settings.load_balancing_first_offset % nested_pools.size();
const LoadBalancing load_balancing = LoadBalancing(settings.load_balancing);
return get_priority_load_balancing.getPriorityFunc(load_balancing, offset, nested_pools.size());
const size_t offset = settings[Setting::load_balancing_first_offset] % nested_pools.size();
return get_priority_load_balancing.getPriorityFunc(settings[Setting::load_balancing], offset, nested_pools.size());
}
std::vector<ConnectionPoolWithFailover::TryResult> ConnectionPoolWithFailover::getManyImpl(
@ -195,11 +203,11 @@ std::vector<ConnectionPoolWithFailover::TryResult> ConnectionPoolWithFailover::g
"Cannot get connection from ConnectionPoolWithFailover cause nested pools are empty");
if (!skip_unavailable_endpoints.has_value())
skip_unavailable_endpoints = settings.skip_unavailable_shards;
skip_unavailable_endpoints = settings[Setting::skip_unavailable_shards];
size_t min_entries = skip_unavailable_endpoints.value() ? 0 : 1;
size_t max_tries = settings.connections_with_failover_max_tries;
size_t max_tries = settings[Setting::connections_with_failover_max_tries];
size_t max_entries;
if (pool_mode == PoolMode::GET_ALL)
{
@ -212,7 +220,7 @@ std::vector<ConnectionPoolWithFailover::TryResult> ConnectionPoolWithFailover::g
}
else if (pool_mode == PoolMode::GET_MANY)
{
max_entries = settings.max_parallel_replicas;
max_entries = settings[Setting::max_parallel_replicas];
}
else
{
@ -222,8 +230,8 @@ std::vector<ConnectionPoolWithFailover::TryResult> ConnectionPoolWithFailover::g
if (!priority_func)
priority_func = makeGetPriorityFunc(settings);
UInt64 max_ignored_errors = settings.distributed_replica_max_ignored_errors.value;
bool fallback_to_stale_replicas = settings.fallback_to_stale_replicas_for_distributed_queries.value;
UInt64 max_ignored_errors = settings[Setting::distributed_replica_max_ignored_errors].value;
bool fallback_to_stale_replicas = settings[Setting::fallback_to_stale_replicas_for_distributed_queries].value;
return Base::getMany(min_entries, max_entries, max_tries, max_ignored_errors, fallback_to_stale_replicas, skip_read_only_replicas, try_get_entry, priority_func);
}
@ -272,7 +280,7 @@ ConnectionPoolWithFailover::getShuffledPools(const Settings & settings, GetPrior
if (!priority_func)
priority_func = makeGetPriorityFunc(settings);
UInt64 max_ignored_errors = settings.distributed_replica_max_ignored_errors.value;
UInt64 max_ignored_errors = settings[Setting::distributed_replica_max_ignored_errors].value;
return Base::getShuffledPools(max_ignored_errors, priority_func, use_slowdown_count);
}

View File

@ -14,6 +14,21 @@ namespace ProfileEvents
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_changing_replica_until_first_data_packet;
extern const SettingsBool allow_experimental_analyzer;
extern const SettingsUInt64 connections_with_failover_max_tries;
extern const SettingsDialect dialect;
extern const SettingsBool fallback_to_stale_replicas_for_distributed_queries;
extern const SettingsUInt64 group_by_two_level_threshold;
extern const SettingsUInt64 group_by_two_level_threshold_bytes;
extern const SettingsNonZeroUInt64 max_parallel_replicas;
extern const SettingsUInt64 parallel_replicas_count;
extern const SettingsUInt64 parallel_replica_offset;
extern const SettingsBool skip_unavailable_shards;
}
namespace ErrorCodes
{
extern const int MISMATCH_REPLICAS_DATA_SOURCES;
@ -32,15 +47,15 @@ HedgedConnections::HedgedConnections(
AsyncCallback async_callback,
GetPriorityForLoadBalancing::Func priority_func)
: hedged_connections_factory(
pool_,
context_->getSettingsRef(),
timeouts_,
context_->getSettingsRef().connections_with_failover_max_tries.value,
context_->getSettingsRef().fallback_to_stale_replicas_for_distributed_queries.value,
context_->getSettingsRef().max_parallel_replicas.value,
context_->getSettingsRef().skip_unavailable_shards.value,
table_to_check_,
priority_func)
pool_,
context_->getSettingsRef(),
timeouts_,
context_->getSettingsRef()[Setting::connections_with_failover_max_tries].value,
context_->getSettingsRef()[Setting::fallback_to_stale_replicas_for_distributed_queries].value,
context_->getSettingsRef()[Setting::max_parallel_replicas].value,
context_->getSettingsRef()[Setting::skip_unavailable_shards].value,
table_to_check_,
priority_func)
, context(std::move(context_))
, settings(context->getSettingsRef())
, throttler(throttler_)
@ -178,29 +193,29 @@ void HedgedConnections::sendQuery(
Settings modified_settings = settings;
/// Queries in foreign languages are transformed to ClickHouse-SQL. Ensure the setting before sending.
modified_settings.dialect = Dialect::clickhouse;
modified_settings.dialect.changed = false;
modified_settings[Setting::dialect] = Dialect::clickhouse;
modified_settings[Setting::dialect].changed = false;
if (disable_two_level_aggregation)
{
/// Disable two-level aggregation due to version incompatibility.
modified_settings.group_by_two_level_threshold = 0;
modified_settings.group_by_two_level_threshold_bytes = 0;
modified_settings[Setting::group_by_two_level_threshold] = 0;
modified_settings[Setting::group_by_two_level_threshold_bytes] = 0;
}
const bool enable_offset_parallel_processing = context->canUseOffsetParallelReplicas();
if (offset_states.size() > 1 && enable_offset_parallel_processing)
{
modified_settings.parallel_replicas_count = offset_states.size();
modified_settings.parallel_replica_offset = fd_to_replica_location[replica.packet_receiver->getFileDescriptor()].offset;
modified_settings[Setting::parallel_replicas_count] = offset_states.size();
modified_settings[Setting::parallel_replica_offset] = fd_to_replica_location[replica.packet_receiver->getFileDescriptor()].offset;
}
/// FIXME: Remove once we will make `allow_experimental_analyzer` obsolete setting.
/// Make the analyzer being set, so it will be effectively applied on the remote server.
/// In other words, the initiator always controls whether the analyzer enabled or not for
/// all servers involved in the distributed query processing.
modified_settings.set("allow_experimental_analyzer", static_cast<bool>(modified_settings.allow_experimental_analyzer));
modified_settings.set("allow_experimental_analyzer", static_cast<bool>(modified_settings[Setting::allow_experimental_analyzer]));
replica.connection->sendQuery(
timeouts, query, /* query_parameters */ {}, query_id, stage, &modified_settings, &client_info, with_pending_data, {});
@ -446,7 +461,7 @@ Packet HedgedConnections::receivePacketFromReplica(const ReplicaLocation & repli
{
/// If we are allowed to change replica until the first data packet,
/// just restart timeout (if it hasn't expired yet). Otherwise disable changing replica with this offset.
if (settings.allow_changing_replica_until_first_data_packet && !replica.is_change_replica_timeout_expired)
if (settings[Setting::allow_changing_replica_until_first_data_packet] && !replica.is_change_replica_timeout_expired)
replica.change_replica_timeout.setRelative(hedged_connections_factory.getConnectionTimeouts().receive_data_timeout);
else
disableChangingReplica(replica_location);

View File

@ -23,6 +23,17 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_settings_after_format_in_insert;
extern const SettingsDialect dialect;
extern const SettingsBool input_format_defaults_for_omitted_fields;
extern const SettingsUInt64 interactive_delay;
extern const SettingsUInt64 max_insert_block_size;
extern const SettingsUInt64 max_parser_backtracks;
extern const SettingsUInt64 max_parser_depth;
extern const SettingsUInt64 max_query_size;
}
namespace ErrorCodes
{
@ -158,21 +169,38 @@ void LocalConnection::sendQuery(
const auto & settings = context->getSettingsRef();
const char * begin = state->query.data();
const char * end = begin + state->query.size();
const Dialect & dialect = settings.dialect;
const Dialect & dialect = settings[Setting::dialect];
std::unique_ptr<IParserBase> parser;
if (dialect == Dialect::kusto)
parser = std::make_unique<ParserKQLStatement>(end, settings.allow_settings_after_format_in_insert);
parser = std::make_unique<ParserKQLStatement>(end, settings[Setting::allow_settings_after_format_in_insert]);
else if (dialect == Dialect::prql)
parser = std::make_unique<ParserPRQLQuery>(settings.max_query_size, settings.max_parser_depth, settings.max_parser_backtracks);
parser
= std::make_unique<ParserPRQLQuery>(settings[Setting::max_query_size], settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks]);
else
parser = std::make_unique<ParserQuery>(end, settings.allow_settings_after_format_in_insert);
parser = std::make_unique<ParserQuery>(end, settings[Setting::allow_settings_after_format_in_insert]);
ASTPtr parsed_query;
if (dialect == Dialect::kusto)
parsed_query = parseKQLQueryAndMovePosition(*parser, begin, end, "", /*allow_multi_statements*/false, settings.max_query_size, settings.max_parser_depth, settings.max_parser_backtracks);
parsed_query = parseKQLQueryAndMovePosition(
*parser,
begin,
end,
"",
/*allow_multi_statements*/ false,
settings[Setting::max_query_size],
settings[Setting::max_parser_depth],
settings[Setting::max_parser_backtracks]);
else
parsed_query = parseQueryAndMovePosition(*parser, begin, end, "", /*allow_multi_statements*/false, settings.max_query_size, settings.max_parser_depth, settings.max_parser_backtracks);
parsed_query = parseQueryAndMovePosition(
*parser,
begin,
end,
"",
/*allow_multi_statements*/ false,
settings[Setting::max_query_size],
settings[Setting::max_parser_depth],
settings[Setting::max_parser_backtracks]);
if (const auto * insert = parsed_query->as<ASTInsertQuery>())
{
@ -180,7 +208,7 @@ void LocalConnection::sendQuery(
current_format = insert->format;
}
auto source = context->getInputFormat(current_format, *in, sample, context->getSettingsRef().max_insert_block_size);
auto source = context->getInputFormat(current_format, *in, sample, context->getSettingsRef()[Setting::max_insert_block_size]);
Pipe pipe(source);
auto columns_description = metadata_snapshot->getColumns();
@ -227,7 +255,7 @@ void LocalConnection::sendQuery(
}
const auto & table_id = query_context->getInsertionTable();
if (query_context->getSettingsRef().input_format_defaults_for_omitted_fields)
if (query_context->getSettingsRef()[Setting::input_format_defaults_for_omitted_fields])
{
if (!table_id.empty())
{
@ -255,7 +283,7 @@ void LocalConnection::sendQuery(
return false;
};
executor.setCancelCallback(callback, query_context->getSettingsRef().interactive_delay / 1000);
executor.setCancelCallback(callback, query_context->getSettingsRef()[Setting::interactive_delay] / 1000);
}
executor.execute();
}
@ -312,7 +340,7 @@ void LocalConnection::sendCancel()
bool LocalConnection::pullBlock(Block & block)
{
if (state->executor)
return state->executor->pull(block, query_context->getSettingsRef().interactive_delay / 1000);
return state->executor->pull(block, query_context->getSettingsRef()[Setting::interactive_delay] / 1000);
return false;
}
@ -466,14 +494,15 @@ bool LocalConnection::poll(size_t)
bool LocalConnection::needSendProgressOrMetrics()
{
if (send_progress && (state->after_send_progress.elapsedMicroseconds() >= query_context->getSettingsRef().interactive_delay))
if (send_progress && (state->after_send_progress.elapsedMicroseconds() >= query_context->getSettingsRef()[Setting::interactive_delay]))
{
state->after_send_progress.restart();
next_packet_type = Protocol::Server::Progress;
return true;
}
if (send_profile_events && (state->after_send_profile_events.elapsedMicroseconds() >= query_context->getSettingsRef().interactive_delay))
if (send_profile_events
&& (state->after_send_profile_events.elapsedMicroseconds() >= query_context->getSettingsRef()[Setting::interactive_delay]))
{
sendProfileEvents();
return true;

View File

@ -12,6 +12,16 @@
namespace DB
{
namespace Setting
{
extern const SettingsBool allow_experimental_analyzer;
extern const SettingsDialect dialect;
extern const SettingsUInt64 group_by_two_level_threshold;
extern const SettingsUInt64 group_by_two_level_threshold_bytes;
extern const SettingsUInt64 parallel_replicas_count;
extern const SettingsUInt64 parallel_replica_offset;
extern const SettingsSeconds receive_timeout;
}
// NOLINTBEGIN(bugprone-undefined-memory-manipulation)
@ -128,8 +138,8 @@ void MultiplexedConnections::sendQuery(
Settings modified_settings = settings;
/// Queries in foreign languages are transformed to ClickHouse-SQL. Ensure the setting before sending.
modified_settings.dialect = Dialect::clickhouse;
modified_settings.dialect.changed = false;
modified_settings[Setting::dialect] = Dialect::clickhouse;
modified_settings[Setting::dialect].changed = false;
for (auto & replica : replica_states)
{
@ -139,8 +149,8 @@ void MultiplexedConnections::sendQuery(
if (replica.connection->getServerRevision(timeouts) < DBMS_MIN_REVISION_WITH_CURRENT_AGGREGATION_VARIANT_SELECTION_METHOD)
{
/// Disable two-level aggregation due to version incompatibility.
modified_settings.group_by_two_level_threshold = 0;
modified_settings.group_by_two_level_threshold_bytes = 0;
modified_settings[Setting::group_by_two_level_threshold] = 0;
modified_settings[Setting::group_by_two_level_threshold_bytes] = 0;
}
}
@ -154,7 +164,7 @@ void MultiplexedConnections::sendQuery(
/// Make the analyzer being set, so it will be effectively applied on the remote server.
/// In other words, the initiator always controls whether the analyzer enabled or not for
/// all servers involved in the distributed query processing.
modified_settings.set("allow_experimental_analyzer", static_cast<bool>(modified_settings.allow_experimental_analyzer));
modified_settings.set("allow_experimental_analyzer", static_cast<bool>(modified_settings[Setting::allow_experimental_analyzer]));
const bool enable_offset_parallel_processing = context->canUseOffsetParallelReplicas();
@ -163,12 +173,12 @@ void MultiplexedConnections::sendQuery(
{
if (enable_offset_parallel_processing)
/// Use multiple replicas for parallel query processing.
modified_settings.parallel_replicas_count = num_replicas;
modified_settings[Setting::parallel_replicas_count] = num_replicas;
for (size_t i = 0; i < num_replicas; ++i)
{
if (enable_offset_parallel_processing)
modified_settings.parallel_replica_offset = i;
modified_settings[Setting::parallel_replica_offset] = i;
replica_states[i].connection->sendQuery(
timeouts, query, /* query_parameters */ {}, query_id, stage, &modified_settings, &client_info, with_pending_data, {});
@ -403,7 +413,7 @@ MultiplexedConnections::ReplicaState & MultiplexedConnections::getReplicaForRead
Poco::Net::Socket::SocketList write_list;
Poco::Net::Socket::SocketList except_list;
auto timeout = settings.receive_timeout;
auto timeout = settings[Setting::receive_timeout];
int n = 0;
/// EINTR loop

View File

@ -1,2 +1,2 @@
clickhouse_add_executable(test-connect test_connect.cpp)
target_link_libraries (test-connect PRIVATE dbms)
target_link_libraries (test-connect PRIVATE dbms clickhouse_functions)

View File

@ -816,6 +816,22 @@ void ColumnDynamic::updateHashWithValue(size_t n, SipHash & hash) const
return;
}
/// If it's not null we update hash with the type name and the actual value.
/// If value in this row is in shared variant, deserialize type and value and
/// update hash with it.
if (discr == getSharedVariantDiscriminator())
{
auto value = getSharedVariant().getDataAt(variant_col.offsetAt(n));
ReadBufferFromMemory buf(value.data, value.size);
auto type = decodeDataType(buf);
hash.update(type->getName());
auto tmp_column = type->createColumn();
type->getDefaultSerialization()->deserializeBinary(*tmp_column, buf, getFormatSettings());
tmp_column->updateHashWithValue(0, hash);
return;
}
hash.update(variant_info.variant_names[discr]);
variant_col.getVariantByGlobalDiscriminator(discr).updateHashWithValue(variant_col.offsetAt(n), hash);
}

View File

@ -47,15 +47,21 @@ ColumnObject::ColumnObject(
, statistics(statistics_)
{
typed_paths.reserve(typed_paths_.size());
sorted_typed_paths.reserve(typed_paths_.size());
for (auto & [path, column] : typed_paths_)
typed_paths[path] = std::move(column);
{
auto it = typed_paths.emplace(path, std::move(column)).first;
sorted_typed_paths.push_back(it->first);
}
std::sort(sorted_typed_paths.begin(), sorted_typed_paths.end());
dynamic_paths.reserve(dynamic_paths_.size());
dynamic_paths_ptrs.reserve(dynamic_paths_.size());
for (auto & [path, column] : dynamic_paths_)
{
dynamic_paths[path] = std::move(column);
dynamic_paths_ptrs[path] = assert_cast<ColumnDynamic *>(dynamic_paths[path].get());
auto it = dynamic_paths.emplace(path, std::move(column)).first;
dynamic_paths_ptrs[path] = assert_cast<ColumnDynamic *>(it->second.get());
sorted_dynamic_paths.insert(it->first);
}
}
@ -64,13 +70,17 @@ ColumnObject::ColumnObject(
: max_dynamic_paths(max_dynamic_paths_), global_max_dynamic_paths(max_dynamic_paths_), max_dynamic_types(max_dynamic_types_)
{
typed_paths.reserve(typed_paths_.size());
sorted_typed_paths.reserve(typed_paths_.size());
for (auto & [path, column] : typed_paths_)
{
if (!column->empty())
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unexpected non-empty typed path column in ColumnObject constructor");
typed_paths[path] = std::move(column);
auto it = typed_paths.emplace(path, std::move(column)).first;
sorted_typed_paths.push_back(it->first);
}
std::sort(sorted_typed_paths.begin(), sorted_typed_paths.end());
MutableColumns paths_and_values;
paths_and_values.emplace_back(ColumnString::create());
paths_and_values.emplace_back(ColumnString::create());
@ -129,13 +139,8 @@ std::string ColumnObject::getName() const
ss << "Object(";
ss << "max_dynamic_paths=" << global_max_dynamic_paths;
ss << ", max_dynamic_types=" << max_dynamic_types;
std::vector<String> sorted_typed_paths;
sorted_typed_paths.reserve(typed_paths.size());
for (const auto & [path, column] : typed_paths)
sorted_typed_paths.push_back(path);
std::sort(sorted_typed_paths.begin(), sorted_typed_paths.end());
for (const auto & path : sorted_typed_paths)
ss << ", " << path << " " << typed_paths.at(path)->getName();
ss << ", " << path << " " << typed_paths.find(path)->second->getName();
ss << ")";
return ss.str();
}
@ -260,6 +265,7 @@ ColumnDynamic * ColumnObject::tryToAddNewDynamicPath(std::string_view path)
new_dynamic_column->insertManyDefaults(size());
auto it = dynamic_paths.emplace(path, std::move(new_dynamic_column)).first;
auto it_ptr = dynamic_paths_ptrs.emplace(path, assert_cast<ColumnDynamic *>(it->second.get())).first;
sorted_dynamic_paths.insert(it->first);
return it_ptr->second;
}
@ -288,8 +294,9 @@ void ColumnObject::setDynamicPaths(const std::vector<String> & paths)
auto new_dynamic_column = ColumnDynamic::create(max_dynamic_types);
if (size)
new_dynamic_column->insertManyDefaults(size);
dynamic_paths[path] = std::move(new_dynamic_column);
dynamic_paths_ptrs[path] = assert_cast<ColumnDynamic *>(dynamic_paths[path].get());
auto it = dynamic_paths.emplace(path, std::move(new_dynamic_column)).first;
dynamic_paths_ptrs[path] = assert_cast<ColumnDynamic *>(it->second.get());
sorted_dynamic_paths.insert(it->first);
}
}
@ -658,39 +665,61 @@ void ColumnObject::popBack(size_t n)
StringRef ColumnObject::serializeValueIntoArena(size_t n, Arena & arena, const char *& begin) const
{
StringRef res(begin, 0);
// Serialize all paths and values in binary format.
/// First serialize values from typed paths in sorted order. They are the same for all instances of this column.
for (auto path : sorted_typed_paths)
{
auto data_ref = typed_paths.find(path)->second->serializeValueIntoArena(n, arena, begin);
res.data = data_ref.data - res.size;
res.size += data_ref.size;
}
/// Second, serialize paths and values in bunary format from dynamic paths and shared data in sorted by path order.
/// Calculate total number of paths to serialize and write it.
const auto & shared_data_offsets = getSharedDataOffsets();
size_t offset = shared_data_offsets[static_cast<ssize_t>(n) - 1];
size_t end = shared_data_offsets[static_cast<ssize_t>(n)];
size_t num_paths = typed_paths.size() + dynamic_paths.size() + (end - offset);
size_t num_paths = (end - offset);
/// Don't serialize Nulls from dynamic paths.
for (const auto & [_, column] : dynamic_paths)
num_paths += !column->isNullAt(n);
char * pos = arena.allocContinue(sizeof(size_t), begin);
memcpy(pos, &num_paths, sizeof(size_t));
res.data = pos - res.size;
res.size += sizeof(size_t);
/// Serialize paths and values from typed paths.
for (const auto & [path, column] : typed_paths)
{
size_t path_size = path.size();
pos = arena.allocContinue(sizeof(size_t) + path_size, begin);
memcpy(pos, &path_size, sizeof(size_t));
memcpy(pos + sizeof(size_t), path.data(), path_size);
auto data_ref = column->serializeValueIntoArena(n, arena, begin);
res.data = data_ref.data - res.size - sizeof(size_t) - path_size;
res.size += data_ref.size + sizeof(size_t) + path_size;
}
/// Serialize paths and values from dynamic paths.
for (const auto & [path, column] : dynamic_paths)
{
WriteBufferFromOwnString buf;
getDynamicSerialization()->serializeBinary(*column, n, buf, getFormatSettings());
serializePathAndValueIntoArena(arena, begin, path, buf.str(), res);
}
/// Serialize paths and values from shared data.
auto dynamic_paths_it = sorted_dynamic_paths.begin();
auto [shared_data_paths, shared_data_values] = getSharedDataPathsAndValues();
for (size_t i = offset; i != end; ++i)
serializePathAndValueIntoArena(arena, begin, shared_data_paths->getDataAt(i), shared_data_values->getDataAt(i), res);
{
auto path = shared_data_paths->getDataAt(i).toView();
/// Paths in shared data are sorted. Serialize all paths from dynamic paths that go before this path in sorted order.
while (dynamic_paths_it != sorted_dynamic_paths.end() && *dynamic_paths_it < path)
{
const auto * dynamic_column = dynamic_paths_ptrs.find(*dynamic_paths_it)->second;
/// Don't serialize Nulls.
if (!dynamic_column->isNullAt(n))
{
WriteBufferFromOwnString buf;
getDynamicSerialization()->serializeBinary(*dynamic_column, n, buf, getFormatSettings());
serializePathAndValueIntoArena(arena, begin, StringRef(*dynamic_paths_it), buf.str(), res);
}
++dynamic_paths_it;
}
serializePathAndValueIntoArena(arena, begin, StringRef(path), shared_data_values->getDataAt(i), res);
}
/// Serialize all remaining paths in dynamic paths.
for (; dynamic_paths_it != sorted_dynamic_paths.end(); ++dynamic_paths_it)
{
const auto * dynamic_column = dynamic_paths_ptrs.find(*dynamic_paths_it)->second;
if (!dynamic_column->isNullAt(n))
{
WriteBufferFromOwnString buf;
getDynamicSerialization()->serializeBinary(*dynamic_column, n, buf, getFormatSettings());
serializePathAndValueIntoArena(arena, begin, StringRef(*dynamic_paths_it), buf.str(), res);
}
}
return res;
}
@ -711,70 +740,49 @@ void ColumnObject::serializePathAndValueIntoArena(DB::Arena & arena, const char
const char * ColumnObject::deserializeAndInsertFromArena(const char * pos)
{
size_t current_size = size();
/// Deserialize paths and values and insert them into typed paths, dynamic paths or shared data.
/// Serialized paths could be unsorted, so we will have to sort all paths that will be inserted into shared data.
std::vector<std::pair<std::string_view, std::string_view>> paths_and_values_for_shared_data;
/// First deserialize typed paths. They come first.
for (auto path : sorted_typed_paths)
pos = typed_paths.find(path)->second->deserializeAndInsertFromArena(pos);
/// Second deserialize all other paths and values and insert them into dynamic paths or shared data.
auto num_paths = unalignedLoad<size_t>(pos);
pos += sizeof(size_t);
const auto [shared_data_paths, shared_data_values] = getSharedDataPathsAndValues();
for (size_t i = 0; i != num_paths; ++i)
{
auto path_size = unalignedLoad<size_t>(pos);
pos += sizeof(size_t);
std::string_view path(pos, path_size);
pos += path_size;
/// Check if it's a typed path. In this case we should use
/// deserializeAndInsertFromArena of corresponding column.
if (auto typed_it = typed_paths.find(path); typed_it != typed_paths.end())
/// Deserialize binary value and try to insert it to dynamic paths or shared data.
auto value_size = unalignedLoad<size_t>(pos);
pos += sizeof(size_t);
std::string_view value(pos, value_size);
pos += value_size;
/// Check if we have this path in dynamic paths.
if (auto dynamic_it = dynamic_paths.find(path); dynamic_it != dynamic_paths.end())
{
pos = typed_it->second->deserializeAndInsertFromArena(pos);
ReadBufferFromMemory buf(value.data(), value.size());
getDynamicSerialization()->deserializeBinary(*dynamic_it->second, buf, getFormatSettings());
}
/// If it's not a typed path, deserialize binary value and try to insert it
/// to dynamic paths or shared data.
/// Try to add a new dynamic path.
else if (auto * dynamic_path_column = tryToAddNewDynamicPath(path))
{
ReadBufferFromMemory buf(value.data(), value.size());
getDynamicSerialization()->deserializeBinary(*dynamic_path_column, buf, getFormatSettings());
}
/// Limit on dynamic paths is reached, add this path to shared data.
/// Serialized paths are sorted, so we can insert right away.
else
{
auto value_size = unalignedLoad<size_t>(pos);
pos += sizeof(size_t);
std::string_view value(pos, value_size);
pos += value_size;
/// Check if we have this path in dynamic paths.
if (auto dynamic_it = dynamic_paths.find(path); dynamic_it != dynamic_paths.end())
{
ReadBufferFromMemory buf(value.data(), value.size());
getDynamicSerialization()->deserializeBinary(*dynamic_it->second, buf, getFormatSettings());
}
/// Try to add a new dynamic path.
else if (auto * dynamic_path_column = tryToAddNewDynamicPath(path))
{
ReadBufferFromMemory buf(value.data(), value.size());
getDynamicSerialization()->deserializeBinary(*dynamic_path_column, buf, getFormatSettings());
}
/// Limit on dynamic paths is reached, add this path to shared data later.
else
{
paths_and_values_for_shared_data.emplace_back(path, value);
}
shared_data_paths->insertData(path.data(), path.size());
shared_data_values->insertData(value.data(), value.size());
}
}
/// Sort and insert all paths from paths_and_values_for_shared_data into shared data.
std::sort(paths_and_values_for_shared_data.begin(), paths_and_values_for_shared_data.end());
const auto [shared_data_paths, shared_data_values] = getSharedDataPathsAndValues();
for (const auto & [path, value] : paths_and_values_for_shared_data)
{
shared_data_paths->insertData(path.data(), path.size());
shared_data_values->insertData(value.data(), value.size());
}
getSharedDataOffsets().push_back(shared_data_paths->size());
/// Insert default value in all remaining typed and dynamic paths.
for (auto & [_, column] : typed_paths)
{
if (column->size() == current_size)
column->insertDefault();
}
/// Insert default value in all remaining dynamic paths.
for (auto & [_, column] : dynamic_paths_ptrs)
{
if (column->size() == current_size)
@ -786,6 +794,11 @@ const char * ColumnObject::deserializeAndInsertFromArena(const char * pos)
const char * ColumnObject::skipSerializedInArena(const char * pos) const
{
/// First, skip all values of typed paths;
for (auto path : sorted_typed_paths)
pos = typed_paths.find(path)->second->skipSerializedInArena(pos);
/// Second, skip all other paths and values.
auto num_paths = unalignedLoad<size_t>(pos);
pos += sizeof(size_t);
for (size_t i = 0; i != num_paths; ++i)
@ -794,15 +807,8 @@ const char * ColumnObject::skipSerializedInArena(const char * pos) const
pos += sizeof(size_t);
std::string_view path(pos, path_size);
pos += path_size;
if (auto typed_it = typed_paths.find(path); typed_it != typed_paths.end())
{
pos = typed_it->second->skipSerializedInArena(pos);
}
else
{
auto value_size = unalignedLoad<size_t>(pos);
pos += sizeof(size_t) + value_size;
}
auto value_size = unalignedLoad<size_t>(pos);
pos += sizeof(size_t) + value_size;
}
return pos;
@ -810,11 +816,51 @@ const char * ColumnObject::skipSerializedInArena(const char * pos) const
void ColumnObject::updateHashWithValue(size_t n, SipHash & hash) const
{
for (const auto & [_, column] : typed_paths)
column->updateHashWithValue(n, hash);
for (const auto & [_, column] : dynamic_paths_ptrs)
column->updateHashWithValue(n, hash);
shared_data->updateHashWithValue(n, hash);
for (auto path : sorted_typed_paths)
typed_paths.find(path)->second->updateHashWithValue(n, hash);
/// The hash of the object in row should not depend on the way we store paths (in dynamic paths or in shared data)
/// and should be the same for the same objects. To support it we update hash with path and its value (if not null) in
/// sorted by path order from both dynamic paths and shared data.
const auto [shared_data_paths, shared_data_values] = getSharedDataPathsAndValues();
const auto & shared_data_offsets = getSharedDataOffsets();
size_t start = shared_data_offsets[static_cast<ssize_t>(n) - 1];
size_t end = shared_data_offsets[static_cast<ssize_t>(n)];
auto dynamic_paths_it = sorted_dynamic_paths.begin();
for (size_t i = start; i != end; ++i)
{
auto path = shared_data_paths->getDataAt(i).toView();
/// Paths in shared data are sorted. Update hash with all paths from dynamic paths that go before this path in sorted order.
while (dynamic_paths_it != sorted_dynamic_paths.end() && *dynamic_paths_it < path)
{
const auto * dynamic_column = dynamic_paths_ptrs.find(*dynamic_paths_it)->second;
if (!dynamic_column->isNullAt(n))
{
hash.update(*dynamic_paths_it);
dynamic_column->updateHashWithValue(n, hash);
}
++dynamic_paths_it;
}
/// Deserialize value in temporary column to get its hash.
auto value = shared_data_values->getDataAt(i);
ReadBufferFromMemory buf(value.data, value.size);
auto tmp_column = ColumnDynamic::create();
getDynamicSerialization()->deserializeBinary(*tmp_column, buf, getFormatSettings());
hash.update(path);
tmp_column->updateHashWithValue(0, hash);
}
/// Iterate over all remaining paths in dynamic paths.
for (; dynamic_paths_it != sorted_dynamic_paths.end(); ++dynamic_paths_it)
{
const auto * dynamic_column = dynamic_paths_ptrs.find(*dynamic_paths_it)->second;
if (!dynamic_column->isNullAt(n))
{
hash.update(*dynamic_paths_it);
dynamic_column->updateHashWithValue(n, hash);
}
}
}
WeakHash32 ColumnObject::getWeakHash32() const
@ -1310,6 +1356,7 @@ void ColumnObject::takeDynamicStructureFromSourceColumns(const DB::Columns & sou
/// Reset current state.
dynamic_paths.clear();
dynamic_paths_ptrs.clear();
sorted_dynamic_paths.clear();
max_dynamic_paths = global_max_dynamic_paths;
Statistics new_statistics(Statistics::Source::MERGE);
@ -1328,8 +1375,9 @@ void ColumnObject::takeDynamicStructureFromSourceColumns(const DB::Columns & sou
{
if (dynamic_paths.size() < max_dynamic_paths)
{
dynamic_paths.emplace(path, ColumnDynamic::create(max_dynamic_types));
dynamic_paths_ptrs.emplace(path, assert_cast<ColumnDynamic *>(dynamic_paths.find(path)->second.get()));
auto it = dynamic_paths.emplace(path, ColumnDynamic::create(max_dynamic_types)).first;
dynamic_paths_ptrs.emplace(path, assert_cast<ColumnDynamic *>(it->second.get()));
sorted_dynamic_paths.insert(it->first);
}
/// Add all remaining paths into shared data statistics until we reach its max size;
else if (new_statistics.shared_data_paths_statistics.size() < Statistics::MAX_SHARED_DATA_STATISTICS_SIZE)
@ -1343,8 +1391,9 @@ void ColumnObject::takeDynamicStructureFromSourceColumns(const DB::Columns & sou
{
for (const auto & [path, _] : path_to_total_number_of_non_null_values)
{
dynamic_paths[path] = ColumnDynamic::create(max_dynamic_types);
dynamic_paths_ptrs[path] = assert_cast<ColumnDynamic *>(dynamic_paths[path].get());
auto it = dynamic_paths.emplace(path, ColumnDynamic::create(max_dynamic_types)).first;
dynamic_paths_ptrs[path] = assert_cast<ColumnDynamic *>(it->second.get());
sorted_dynamic_paths.insert(it->first);
}
}

View File

@ -238,10 +238,15 @@ private:
/// Map path -> column for paths with explicitly specified types.
/// This set of paths is constant and cannot be changed.
PathToColumnMap typed_paths;
/// Sorted list of typed paths. Used to avoid sorting paths every time in some methods.
std::vector<std::string_view> sorted_typed_paths;
/// Map path -> column for dynamically added paths. All columns
/// here are Dynamic columns. This set of paths can be extended
/// during inerts into the column.
PathToColumnMap dynamic_paths;
/// Sorted list of dynamic paths. Used to avoid sorting paths every time in some methods.
std::set<std::string_view> sorted_dynamic_paths;
/// Store and use pointers to ColumnDynamic to avoid virtual calls.
/// With hundreds of dynamic paths these virtual calls are noticeable.
PathToDynamicColumnPtrMap dynamic_paths_ptrs;

View File

@ -1,4 +1,5 @@
clickhouse_add_executable(column_insert_many_from benchmark_column_insert_many_from.cpp)
target_link_libraries (column_insert_many_from PRIVATE
ch_contrib::gbenchmark_all
dbms)
dbms
clickhouse_functions)

View File

@ -13,6 +13,13 @@
#include <filesystem>
#include <fstream>
namespace DB
{
namespace Setting
{
extern const SettingsTimezone session_timezone;
}
}
namespace
{
@ -203,5 +210,5 @@ DateLUT & DateLUT::getInstance()
std::string DateLUT::extractTimezoneFromContext(DB::ContextPtr query_context)
{
return query_context->getSettingsRef().session_timezone.value;
return query_context->getSettingsRef()[DB::Setting::session_timezone].value;
}

View File

@ -0,0 +1,94 @@
#include <chrono>
#include <memory>
#include <Common/KeystrokeInterceptor.h>
#include <termios.h>
#include <unistd.h>
#include <base/defines.h>
namespace DB
{
KeystrokeInterceptor::KeystrokeInterceptor(int fd_) : fd(fd_)
{
}
KeystrokeInterceptor::~KeystrokeInterceptor()
{
stopIntercept();
}
void KeystrokeInterceptor::registerCallback(char key, KeystrokeInterceptor::Callback cb)
{
callbacks.emplace(key, cb);
}
void KeystrokeInterceptor::startIntercept()
{
std::lock_guard<std::mutex> lock(mutex);
if (intercept_thread && intercept_thread->joinable())
return;
chassert(!orig_termios);
stop_requested = false;
/// Save terminal state.
orig_termios = std::make_unique<struct termios>();
tcgetattr(fd, orig_termios.get());
/// Enable raw terminal mode.
struct termios raw = *orig_termios;
raw.c_lflag &= ~(ECHO | ICANON);
raw.c_cc[VMIN] = 0;
raw.c_cc[VTIME] = 1;
tcsetattr(fd, TCSAFLUSH, &raw);
intercept_thread = std::make_unique<std::thread>(&KeystrokeInterceptor::run, this, callbacks);
}
void KeystrokeInterceptor::stopIntercept()
{
stop_requested = true;
std::lock_guard<std::mutex> lock(mutex);
if (intercept_thread && intercept_thread->joinable())
{
intercept_thread->join();
intercept_thread.reset();
}
/// Reset original terminal mode.
if (orig_termios)
{
tcsetattr(fd, TCSAFLUSH, orig_termios.get());
orig_termios.reset();
}
}
void KeystrokeInterceptor::run(KeystrokeInterceptor::CallbackMap map)
{
while (!stop_requested)
{
runImpl(map);
std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
}
void KeystrokeInterceptor::runImpl(const DB::KeystrokeInterceptor::CallbackMap & map) const
{
char ch;
if (read(fd, &ch, 1) > 0)
{
auto it = map.find(ch);
if (it != map.end())
{
auto fn = it->second;
fn();
}
}
}
}

View File

@ -0,0 +1,42 @@
#pragma once
#include <functional>
#include <memory>
#include <mutex>
#include <thread>
#include <unordered_map>
struct termios;
namespace DB
{
class KeystrokeInterceptor
{
using Callback = std::function<void()>;
using CallbackMap = std::unordered_map<char, Callback>;
public:
explicit KeystrokeInterceptor(int fd_);
~KeystrokeInterceptor();
void registerCallback(char key, Callback cb);
void startIntercept();
void stopIntercept();
private:
void run(CallbackMap);
void runImpl(const CallbackMap &) const;
const int fd;
std::mutex mutex;
CallbackMap callbacks;
std::unique_ptr<std::thread> intercept_thread;
std::unique_ptr<struct termios> orig_termios;
std::atomic_bool stop_requested = false;
};
}

View File

@ -1,8 +1,9 @@
#include <Common/NamedCollections/NamedCollectionsFactory.h>
#include <Common/NamedCollections/NamedCollectionConfiguration.h>
#include <Common/NamedCollections/NamedCollectionsMetadataStorage.h>
#include <Core/Settings.h>
#include <base/sleep.h>
#include <Common/FieldVisitorToString.h>
#include <Common/NamedCollections/NamedCollectionConfiguration.h>
#include <Common/NamedCollections/NamedCollectionsFactory.h>
#include <Common/NamedCollections/NamedCollectionsMetadataStorage.h>
namespace DB
{

View File

@ -1,28 +1,36 @@
#include <Common/NamedCollections/NamedCollectionsMetadataStorage.h>
#include <Common/NamedCollections/NamedCollectionConfiguration.h>
#include <Common/escapeForFileName.h>
#include <Common/logger_useful.h>
#include <Common/ZooKeeper/IKeeper.h>
#include <Common/ZooKeeper/KeeperException.h>
#include <Common/ZooKeeper/ZooKeeper.h>
#include <filesystem>
#include <Core/Settings.h>
#include <IO/FileEncryptionCommon.h>
#include <IO/ReadBufferFromFile.h>
#include <IO/ReadBufferFromString.h>
#include <IO/ReadHelpers.h>
#include <IO/WriteBufferFromFile.h>
#include <IO/WriteBufferFromString.h>
#include <IO/WriteHelpers.h>
#include <Parsers/parseQuery.h>
#include <Interpreters/Context.h>
#include <Parsers/ParserCreateQuery.h>
#include <Parsers/formatAST.h>
#include <Interpreters/Context.h>
#include <filesystem>
#include <Parsers/parseQuery.h>
#include <boost/algorithm/hex.hpp>
#include <Common/NamedCollections/NamedCollectionConfiguration.h>
#include <Common/NamedCollections/NamedCollectionsMetadataStorage.h>
#include <Common/ZooKeeper/IKeeper.h>
#include <Common/ZooKeeper/KeeperException.h>
#include <Common/ZooKeeper/ZooKeeper.h>
#include <Common/escapeForFileName.h>
#include <Common/logger_useful.h>
namespace fs = std::filesystem;
namespace DB
{
namespace Setting
{
extern const SettingsBool fsync_metadata;
extern const SettingsUInt64 max_parser_backtracks;
extern const SettingsUInt64 max_parser_depth;
}
namespace ErrorCodes
{
extern const int NAMED_COLLECTION_ALREADY_EXISTS;
@ -157,7 +165,7 @@ public:
writeString(write_data, out);
out.next();
if (getContext()->getSettingsRef().fsync_metadata)
if (getContext()->getSettingsRef()[Setting::fsync_metadata])
out.sync();
out.close();
@ -573,7 +581,7 @@ ASTCreateNamedCollectionQuery NamedCollectionsMetadataStorage::readCreateQuery(c
const auto & settings = getContext()->getSettingsRef();
ParserCreateNamedCollectionQuery parser;
auto ast = parseQuery(parser, query, "in file " + path, 0, settings.max_parser_depth, settings.max_parser_backtracks);
auto ast = parseQuery(parser, query, "in file " + path, 0, settings[Setting::max_parser_depth], settings[Setting::max_parser_backtracks]);
const auto & create_query = ast->as<const ASTCreateNamedCollectionQuery &>();
return create_query;
}

View File

@ -14,6 +14,12 @@
namespace DB
{
namespace Setting
{
extern const SettingsFloat opentelemetry_start_trace_probability;
}
namespace OpenTelemetry
{
@ -329,7 +335,7 @@ TracingContextHolder::TracingContextHolder(
return;
// Start the trace with some configurable probability.
std::bernoulli_distribution should_start_trace{settings_ptr->opentelemetry_start_trace_probability};
std::bernoulli_distribution should_start_trace{(*settings_ptr)[Setting::opentelemetry_start_trace_probability]};
if (!should_start_trace(thread_local_rng))
/// skip tracing context initialization on current thread
return;

File diff suppressed because it is too large Load Diff

View File

@ -149,6 +149,15 @@ namespace ProfileEvents
static const Event num_counters;
};
enum class ValueType : uint8_t
{
Number,
Bytes,
Milliseconds,
Microseconds,
Nanoseconds,
};
/// Increment a counter for event. Thread-safe.
void increment(Event event, Count amount = 1);
@ -165,6 +174,9 @@ namespace ProfileEvents
/// Get description of event by identifier. Returns statically allocated string.
const char * getDocumentation(Event event);
/// Get value type of event by identifier. Returns enum value.
ValueType getValueType(Event event);
/// Get index just after last event identifier.
Event end();

View File

@ -0,0 +1,474 @@
#include "ProgressTable.h"
#include "Common/AllocatorWithMemoryTracking.h"
#include "Common/ProfileEvents.h"
#include "base/defines.h"
#include <Columns/ColumnString.h>
#include <Columns/ColumnsNumber.h>
#include <Core/Block.h>
#include <IO/Operators.h>
#include <IO/WriteBufferFromFileDescriptor.h>
#include <Interpreters/ProfileEventsExt.h>
#include <base/terminalColors.h>
#include <Common/TerminalSize.h>
#include <Common/formatReadable.h>
#include <format>
#include <numeric>
#include <unordered_map>
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
namespace
{
constexpr UInt64 THREAD_GROUP_ID = 0;
constexpr std::string_view CLEAR_TO_END_OF_LINE = "\033[K";
constexpr std::string_view CLEAR_TO_END_OF_SCREEN = "\033[0J";
constexpr std::string_view RESET_COLOR = "\033[0m";
constexpr std::string_view HIDE_CURSOR = "\033[?25l";
constexpr std::string_view SHOW_CURSOR = "\033[?25h";
std::string moveUpNLines(size_t N)
{
return std::format("\033[{}A", N);
}
std::string formatReadableValue(ProfileEvents::ValueType value_type, double value)
{
switch (value_type)
{
case ProfileEvents::ValueType::Number:
return formatReadableQuantity(value, /*precision*/ std::floor(value) == value && fabs(value) < 1000 ? 0 : 2);
case ProfileEvents::ValueType::Bytes:
return formatReadableSizeWithDecimalSuffix(value);
case ProfileEvents::ValueType::Nanoseconds:
return formatReadableTime(value);
case ProfileEvents::ValueType::Microseconds:
return formatReadableTime(value * 1e3);
case ProfileEvents::ValueType::Milliseconds:
return formatReadableTime(value * 1e6);
}
}
const std::unordered_map<std::string_view, ProfileEvents::Event> & getEventNameToEvent()
{
/// TODO: MemoryTracker::USAGE_EVENT_NAME and PEAK_USAGE_EVENT_NAME
static std::unordered_map<std::string_view, ProfileEvents::Event> event_name_to_event;
if (!event_name_to_event.empty())
return event_name_to_event;
for (ProfileEvents::Event event = ProfileEvents::Event(0); event < ProfileEvents::end(); ++event)
{
event_name_to_event.emplace(ProfileEvents::getName(event), event);
}
return event_name_to_event;
}
std::string_view setColorForProgress(double progress, double max_progress)
{
constexpr std::array<std::string_view, 5> colors = {
"\033[38;5;236m", /// Dark Grey
"\033[38;5;250m", /// Light Grey
"\033[38;5;34m", /// Green
"\033[38;5;226m", /// Yellow
"\033[1;33m", /// Bold
};
constexpr std::array<double, 4> fractions = {
0.05,
0.20,
0.80,
0.95,
};
if (max_progress == 0)
return colors.front();
auto fraction = progress / max_progress;
auto dist = std::upper_bound(fractions.begin(), fractions.end(), fraction) - fractions.begin();
return colors[dist];
}
std::string_view setColorForBytesBasedMetricsProgress(double progress)
{
constexpr std::array<std::string_view, 7> colors = {
"\033[38;5;236m", /// Dark Grey
"\033[38;5;250m", /// Light Grey
"\033[38;5;34m", /// Green
"\033[38;5;226m", /// Yellow
"\033[38;5;208m", /// Orange
"\033[1;33m", /// Bold
"\033[38;5;160m", /// Red: corresponds to >= 1T/s. Not realistic, unless there is a bug.
};
/// Bytes.
constexpr std::array<uint64_t, 6> thresholds = {
1LL << 20,
100LL << 20,
1'000LL << 20,
10'000LL << 20,
100'000LL << 20,
1'000'000LL << 20,
};
auto dist = std::upper_bound(thresholds.begin(), thresholds.end(), progress) - thresholds.begin();
return colors[dist];
}
std::string_view setColorForTimeBasedMetricsProgress(ProfileEvents::ValueType value_type, double progress)
{
/// Time units in a second.
auto units = [](ProfileEvents::ValueType t) -> double
{
switch (t)
{
case ProfileEvents::ValueType::Milliseconds:
return 1e3;
case ProfileEvents::ValueType::Microseconds:
return 1e6;
case ProfileEvents::ValueType::Nanoseconds:
return 1e9;
default:
throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong value type, expecting time units");
}
}(value_type);
constexpr std::array<std::string_view, 5> colors = {
"\033[38;5;236m", /// Dark Grey
"\033[38;5;250m", /// Light Grey
"\033[38;5;34m", /// Green
"\033[38;5;226m", /// Yellow
"\033[1;33m" /// Bold
};
const std::array<double, 4> thresholds = {0.001 * units, 0.01 * units, 0.1 * units, 1.0 * units};
auto dist = std::upper_bound(thresholds.begin(), thresholds.end(), progress) - thresholds.begin();
return colors[dist];
}
std::string_view setColorForStaleMetrics()
{
return "\033[38;5;236m"; /// Dark Grey
}
std::string_view setColorForDocumentation()
{
return "\033[38;5;236m"; /// Dark Grey
}
template <typename Out>
void writeWithWidth(Out & out, std::string_view s, size_t width)
{
if (s.size() >= width)
out << s << " ";
else
out << s << std::string(width - s.size(), ' ');
}
template <typename Out>
void writeWithWidthStrict(Out & out, std::string_view s, size_t width)
{
chassert(width != 0);
if (s.size() > width)
out << s.substr(0, width - 1) << "";
else
out << s;
}
}
void ProgressTable::writeTable(WriteBufferFromFileDescriptor & message, bool show_table, bool toggle_enabled)
{
std::lock_guard lock{mutex};
if (!show_table)
{
if (written_first_block)
message << CLEAR_TO_END_OF_SCREEN;
if (toggle_enabled)
{
message << HIDE_CURSOR;
message << "\n";
message << "Press the space key to toggle the display of the progress table.";
message << moveUpNLines(1);
message.next();
}
return;
}
const auto & event_name_to_event = getEventNameToEvent();
size_t terminal_width = getTerminalWidth(in_fd, err_fd);
if (terminal_width < column_event_name_width + COLUMN_VALUE_WIDTH + COLUMN_PROGRESS_WIDTH)
return;
if (metrics.empty())
return;
message << HIDE_CURSOR;
message << "\n";
writeWithWidth(message, COLUMN_EVENT_NAME, column_event_name_width);
writeWithWidth(message, COLUMN_VALUE, COLUMN_VALUE_WIDTH);
writeWithWidth(message, COLUMN_PROGRESS, COLUMN_PROGRESS_WIDTH);
writeWithWidth(message, COLUMN_DOCUMENTATION_NAME, COLUMN_DOCUMENTATION_WIDTH);
message << CLEAR_TO_END_OF_LINE;
double elapsed_sec = watch.elapsedSeconds();
for (auto & [name, per_host_info] : metrics)
{
message << "\n";
if (per_host_info.isStale(elapsed_sec))
message << setColorForStaleMetrics();
writeWithWidth(message, name, column_event_name_width);
auto value = per_host_info.getSummaryValue();
auto value_type = getValueType(event_name_to_event.at(name));
writeWithWidth(message, formatReadableValue(value_type, value), COLUMN_VALUE_WIDTH);
/// Get the maximum progress before it is updated in getSummaryProgress.
auto max_progress = per_host_info.getMaxProgress();
auto progress = per_host_info.getSummaryProgress(elapsed_sec);
switch (value_type)
{
case ProfileEvents::ValueType::Number:
message << setColorForProgress(progress, max_progress);
break;
case ProfileEvents::ValueType::Bytes:
message << setColorForBytesBasedMetricsProgress(progress);
break;
case ProfileEvents::ValueType::Milliseconds:
[[fallthrough]];
case ProfileEvents::ValueType::Microseconds:
[[fallthrough]];
case ProfileEvents::ValueType::Nanoseconds:
message << setColorForTimeBasedMetricsProgress(value_type, progress);
break;
}
writeWithWidth(message, formatReadableValue(value_type, progress) + "/s", COLUMN_PROGRESS_WIDTH);
message << setColorForDocumentation();
const auto * doc = getDocumentation(event_name_to_event.at(name));
writeWithWidthStrict(message, doc, COLUMN_DOCUMENTATION_WIDTH);
message << RESET_COLOR;
message << CLEAR_TO_END_OF_LINE;
}
message << moveUpNLines(tableSize());
message.next();
}
void ProgressTable::writeFinalTable()
{
std::lock_guard lock{mutex};
const auto & event_name_to_event = getEventNameToEvent();
size_t terminal_width = getTerminalWidth(in_fd, err_fd);
if (terminal_width < column_event_name_width + COLUMN_VALUE_WIDTH)
return;
if (metrics.empty())
return;
output_stream << "\n";
writeWithWidth(output_stream, COLUMN_EVENT_NAME, column_event_name_width);
writeWithWidth(output_stream, COLUMN_VALUE, COLUMN_VALUE_WIDTH);
for (auto & [name, per_host_info] : metrics)
{
output_stream << "\n";
writeWithWidth(output_stream, name, column_event_name_width);
auto value = per_host_info.getSummaryValue();
auto value_type = getValueType(event_name_to_event.at(name));
writeWithWidth(output_stream, formatReadableValue(value_type, value), COLUMN_VALUE_WIDTH);
}
}
void ProgressTable::updateTable(const Block & block)
{
const auto & array_thread_id = typeid_cast<const ColumnUInt64 &>(*block.getByName("thread_id").column).getData();
const auto & names = typeid_cast<const ColumnString &>(*block.getByName("name").column);
const auto & host_names = typeid_cast<const ColumnString &>(*block.getByName("host_name").column);
const auto & array_values = typeid_cast<const ColumnInt64 &>(*block.getByName("value").column).getData();
const auto & array_type = typeid_cast<const ColumnInt8 &>(*block.getByName("type").column).getData();
const double time_now = watch.elapsedSeconds();
size_t max_event_name_width = COLUMN_EVENT_NAME.size();
std::lock_guard lock{mutex};
const auto & event_name_to_event = getEventNameToEvent();
for (size_t row_num = 0, rows = block.rows(); row_num < rows; ++row_num)
{
auto thread_id = array_thread_id[row_num];
/// In ProfileEvents packets thread id 0 specifies common profiling information
/// for all threads executing current query on specific host. So instead of summing per thread
/// consumption it's enough to look for data with thread id 0.
if (thread_id != THREAD_GROUP_ID)
continue;
auto value = array_values[row_num];
auto name = names.getDataAt(row_num).toString();
auto host_name = host_names.getDataAt(row_num).toString();
auto type = static_cast<ProfileEvents::Type>(array_type[row_num]);
/// Got unexpected event name.
if (!event_name_to_event.contains(name))
continue;
/// Store non-zero values.
if (value == 0)
continue;
auto it = metrics.find(name);
/// If the table has already been written, then do not add new metrics to avoid jitter.
if (it == metrics.end() && written_first_block)
continue;
if (!written_first_block)
it = metrics.try_emplace(name).first;
it->second.updateHostValue(host_name, type, value, time_now);
max_event_name_width = std::max(max_event_name_width, name.size());
}
if (!written_first_block)
column_event_name_width = max_event_name_width + 1;
written_first_block = true;
}
void ProgressTable::clearTableOutput(WriteBufferFromFileDescriptor & message)
{
message << CLEAR_TO_END_OF_SCREEN;
message << SHOW_CURSOR;
message.next();
}
void ProgressTable::resetTable()
{
std::lock_guard lock{mutex};
watch.restart();
metrics.clear();
written_first_block = false;
}
size_t ProgressTable::tableSize() const
{
/// Number of lines + header.
return metrics.empty() ? 0 : metrics.size() + 1;
}
ProgressTable::MetricInfo::MetricInfo(ProfileEvents::Type t) : type(t)
{
}
void ProgressTable::MetricInfo::updateValue(Int64 new_value, double new_time)
{
/// If the value has not been updated for a long time
/// reset the time in snapshots to a second ago.
if (new_time - new_snapshot.time >= 0.5 || new_snapshot.time == 0)
{
prev_shapshot = {new_snapshot.value, new_time - 1.0};
cur_shapshot = {new_snapshot.value, new_time - 1.0};
}
switch (type)
{
case ProfileEvents::Type::INCREMENT:
new_snapshot.value = new_snapshot.value + new_value;
break;
case ProfileEvents::Type::GAUGE:
new_snapshot.value = new_value;
break;
}
new_snapshot.time = new_time;
if (new_snapshot.time - cur_shapshot.time >= 0.5)
prev_shapshot = std::exchange(cur_shapshot, new_snapshot);
update_time = new_time;
}
bool ProgressTable::MetricInfo::isStale(double now) const
{
return update_time != 0 && now - update_time >= 5.0;
}
double ProgressTable::MetricInfo::calculateProgress(double time_now) const
{
/// If the value has not been updated for a long time, the progress is 0.
if (time_now - new_snapshot.time >= 0.5)
return 0;
return (cur_shapshot.value - prev_shapshot.value) / (cur_shapshot.time - prev_shapshot.time);
}
double ProgressTable::MetricInfo::getValue() const
{
return new_snapshot.value;
}
void ProgressTable::MetricInfoPerHost::updateHostValue(const HostName & host, ProfileEvents::Type type, Int64 new_value, double new_time)
{
auto it = host_to_metric.find(host);
if (it == host_to_metric.end())
it = host_to_metric.emplace(host, type).first;
it->second.updateValue(new_value, new_time);
}
double ProgressTable::MetricInfoPerHost::getSummaryValue()
{
return std::accumulate(
host_to_metric.cbegin(),
host_to_metric.cend(),
0.0,
[](double acc, const auto & host_data)
{
const MetricInfo & info = host_data.second;
return acc + info.getValue();
});
}
double ProgressTable::MetricInfoPerHost::getSummaryProgress(double time_now)
{
auto progress = std::accumulate(
host_to_metric.cbegin(),
host_to_metric.cend(),
0.0,
[time_now](double acc, const auto & host_data)
{
const MetricInfo & info = host_data.second;
return acc + info.calculateProgress(time_now);
});
max_progress = std::max(max_progress, progress);
return progress;
}
double ProgressTable::MetricInfoPerHost::getMaxProgress() const
{
return max_progress;
}
bool ProgressTable::MetricInfoPerHost::isStale(double now) const
{
return std::all_of(host_to_metric.cbegin(), host_to_metric.cend(), [&now](const auto & p) { return p.second.isStale(now); });
}
}

119
src/Common/ProgressTable.h Normal file
View File

@ -0,0 +1,119 @@
#pragma once
#include <Interpreters/ProfileEventsExt.h>
#include <base/types.h>
#include <Common/ProfileEvents.h>
#include <Common/Stopwatch.h>
#include <map>
#include <mutex>
#include <ostream>
#include <string_view>
#include <unistd.h>
#include <unordered_map>
namespace DB
{
class WriteBufferFromFileDescriptor;
class Block;
class ProgressTable
{
public:
explicit ProgressTable(std::ostream & output_stream_, int in_fd_ = STDIN_FILENO, int err_fd_ = STDERR_FILENO)
: output_stream(output_stream_), in_fd(in_fd_), err_fd(err_fd_)
{}
/// Write progress table with metrics.
void writeTable(WriteBufferFromFileDescriptor & message, bool show_table, bool toggle_enabled);
void clearTableOutput(WriteBufferFromFileDescriptor & message);
void writeFinalTable();
/// Update the metric values. They can be updated from:
/// onProfileEvents in clickhouse-client;
void updateTable(const Block & block);
/// Reset progress table values.
void resetTable();
private:
class MetricInfo
{
public:
explicit MetricInfo(ProfileEvents::Type t);
void updateValue(Int64 new_value, double new_time);
double calculateProgress(double time_now) const;
double getValue() const;
bool isStale(double now) const;
private:
const ProfileEvents::Type type;
struct Snapshot
{
Int64 value = 0;
double time = 0;
};
/// The previous and current snapshots are used to calculateProgress.
/// They contain outdated by about a second information.
/// The new snapshot is used to updateValue and getValue.
/// If you use a new snapshot to calculate progress, then the time difference between
/// the previous update will be very small, so progress will jitter.
Snapshot prev_shapshot;
Snapshot cur_shapshot;
Snapshot new_snapshot;
double update_time = 0.0;
};
class MetricInfoPerHost
{
public:
using HostName = String;
void updateHostValue(const HostName & host, ProfileEvents::Type type, Int64 new_value, double new_time);
double getSummaryValue();
double getSummaryProgress(double time_now);
double getMaxProgress() const;
bool isStale(double now) const;
private:
std::unordered_map<HostName, MetricInfo> host_to_metric;
double max_progress = 0;
};
size_t tableSize() const;
using MetricName = String;
/// The server periodically sends Block with profile events.
/// This information is stored here.
std::map<MetricName, MetricInfoPerHost> metrics;
/// It is possible concurrent access to the metrics.
std::mutex mutex;
/// Track query execution time on client.
Stopwatch watch;
bool written_first_block = false;
size_t column_event_name_width = 20;
static constexpr std::string_view COLUMN_EVENT_NAME = "Event name";
static constexpr std::string_view COLUMN_VALUE = "Value";
static constexpr std::string_view COLUMN_PROGRESS = "Progress";
static constexpr std::string_view COLUMN_DOCUMENTATION_NAME = "Documentation";
static constexpr size_t COLUMN_VALUE_WIDTH = 20;
static constexpr size_t COLUMN_PROGRESS_WIDTH = 20;
static constexpr size_t COLUMN_DOCUMENTATION_WIDTH = 100;
std::ostream & output_stream;
int in_fd;
int err_fd;
};
}

View File

@ -2,6 +2,7 @@
#include <Core/Field.h>
#include <vector>
namespace DB
{

View File

@ -2,6 +2,7 @@ clickhouse_add_executable(integer_hash_tables_and_hashes integer_hash_tables_and
target_link_libraries (integer_hash_tables_and_hashes PRIVATE
ch_contrib::gbenchmark_all
dbms
clickhouse_functions
ch_contrib::abseil_swiss_tables
ch_contrib::sparsehash
ch_contrib::wyhash
@ -11,4 +12,5 @@ target_link_libraries (integer_hash_tables_and_hashes PRIVATE
clickhouse_add_executable(orc_string_dictionary orc_string_dictionary.cpp)
target_link_libraries (orc_string_dictionary PRIVATE
ch_contrib::gbenchmark_all
dbms)
dbms
clickhouse_functions)

View File

@ -26,24 +26,24 @@ clickhouse_add_executable (radix_sort radix_sort.cpp)
target_link_libraries (radix_sort PRIVATE clickhouse_common_io clickhouse_common_config ch_contrib::pdqsort)
clickhouse_add_executable (arena_with_free_lists arena_with_free_lists.cpp)
target_link_libraries (arena_with_free_lists PRIVATE dbms)
target_link_libraries (arena_with_free_lists PRIVATE dbms clickhouse_functions)
clickhouse_add_executable (lru_hash_map_perf lru_hash_map_perf.cpp)
target_link_libraries (lru_hash_map_perf PRIVATE dbms)
target_link_libraries (lru_hash_map_perf PRIVATE dbms clickhouse_functions)
if (OS_LINUX)
clickhouse_add_executable (thread_creation_latency thread_creation_latency.cpp)
target_link_libraries (thread_creation_latency PRIVATE clickhouse_common_io clickhouse_common_config)
target_link_libraries (thread_creation_latency PRIVATE dbms clickhouse_functions clickhouse_common_io clickhouse_common_config)
endif()
clickhouse_add_executable (array_cache array_cache.cpp)
target_link_libraries (array_cache PRIVATE clickhouse_common_io clickhouse_common_config)
clickhouse_add_executable (space_saving space_saving.cpp)
target_link_libraries (space_saving PRIVATE clickhouse_common_io clickhouse_common_config)
target_link_libraries (space_saving PRIVATE dbms clickhouse_functions clickhouse_common_io clickhouse_common_config)
clickhouse_add_executable (integer_hash_tables_benchmark integer_hash_tables_benchmark.cpp)
target_link_libraries (integer_hash_tables_benchmark PRIVATE dbms ch_contrib::abseil_swiss_tables ch_contrib::sparsehash)
target_link_libraries (integer_hash_tables_benchmark PRIVATE dbms clickhouse_functions ch_contrib::abseil_swiss_tables ch_contrib::sparsehash)
clickhouse_add_executable (cow_columns cow_columns.cpp)
target_link_libraries (cow_columns PRIVATE clickhouse_common_io clickhouse_common_config)
@ -69,13 +69,13 @@ clickhouse_add_executable (procfs_metrics_provider_perf procfs_metrics_provider_
target_link_libraries (procfs_metrics_provider_perf PRIVATE clickhouse_common_io clickhouse_common_config)
clickhouse_add_executable (average average.cpp)
target_link_libraries (average PRIVATE clickhouse_common_io clickhouse_common_config)
target_link_libraries (average PRIVATE dbms clickhouse_common_io clickhouse_common_config clickhouse_functions)
clickhouse_add_executable (shell_command_inout shell_command_inout.cpp)
target_link_libraries (shell_command_inout PRIVATE clickhouse_common_io clickhouse_common_config)
clickhouse_add_executable (executable_udf executable_udf.cpp)
target_link_libraries (executable_udf PRIVATE dbms)
target_link_libraries (executable_udf PRIVATE dbms clickhouse_functions)
if (ENABLE_HIVE)
clickhouse_add_executable (hive_metastore_client hive_metastore_client.cpp)
@ -83,7 +83,7 @@ if (ENABLE_HIVE)
endif()
clickhouse_add_executable (interval_tree interval_tree.cpp)
target_link_libraries (interval_tree PRIVATE dbms)
target_link_libraries (interval_tree PRIVATE dbms clickhouse_functions)
if (ENABLE_SSL)
clickhouse_add_executable (encrypt_decrypt encrypt_decrypt.cpp)

View File

@ -82,3 +82,16 @@ std::string formatReadableQuantity(double value, int precision)
formatReadableQuantity(value, out, precision);
return out.str();
}
void formatReadableTime(double ns, DB::WriteBuffer & out, int precision)
{
const char * units[] = {" ns", " us", " ms", " s"};
formatReadable(ns, out, precision, units, sizeof(units) / sizeof(units[0]), 1000);
}
std::string formatReadableTime(double ns, int precision)
{
DB::WriteBufferFromOwnString out;
formatReadableTime(ns, out, precision);
return out.str();
}

View File

@ -23,6 +23,9 @@ std::string formatReadableSizeWithDecimalSuffix(double value, int precision = 2)
void formatReadableQuantity(double value, DB::WriteBuffer & out, int precision = 2);
std::string formatReadableQuantity(double value, int precision = 2);
/// Prints the passed time in nanoseconds as 123.45 ms.
void formatReadableTime(double ns, DB::WriteBuffer & out, int precision = 2);
std::string formatReadableTime(double ns, int precision = 2);
/// Wrapper around value. If used with fmt library (e.g. for log messages),
/// value is automatically formatted as size with binary suffix.

View File

@ -1,2 +1,2 @@
clickhouse_add_executable (compressed_buffer compressed_buffer.cpp)
target_link_libraries (compressed_buffer PRIVATE clickhouse_common_io clickhouse_common_config clickhouse_compression)
target_link_libraries (compressed_buffer PRIVATE dbms clickhouse_functions clickhouse_common_io clickhouse_common_config clickhouse_compression)

View File

@ -1,12 +1,13 @@
#pragma once
#include <unordered_map>
#include <Core/SettingsFields.h>
#include <Common/SettingsChanges.h>
#include <Common/FieldVisitorToString.h>
#include <Core/SettingsWriteFormat.h>
#include <IO/Operators.h>
#include <base/range.h>
#include <boost/blank.hpp>
#include <unordered_map>
#include <Common/FieldVisitorToString.h>
#include <Common/SettingsChanges.h>
namespace boost::program_options
@ -20,13 +21,6 @@ namespace DB
class ReadBuffer;
class WriteBuffer;
enum class SettingsWriteFormat : uint8_t
{
BINARY = 0, /// Part of the settings are serialized as strings, and other part as variants. This is the old behaviour.
STRINGS_WITH_FLAGS = 1, /// All settings are serialized as strings. Before each value the flag `is_important` is serialized.
DEFAULT = STRINGS_WITH_FLAGS,
};
/** Template class to define collections of settings.
* Example of usage:
*
@ -96,6 +90,8 @@ public:
static String valueToStringUtil(std::string_view name, const Field & value);
static Field stringToValueUtil(std::string_view name, const String & str);
static std::string_view resolveName(std::string_view name);
void write(WriteBuffer & out, SettingsWriteFormat format = SettingsWriteFormat::DEFAULT) const;
void read(ReadBuffer & in, SettingsWriteFormat format = SettingsWriteFormat::DEFAULT);
@ -191,8 +187,6 @@ public:
MutableRange allMutable(SkipFlags skip_flags = SKIP_NONE) { return MutableRange{*this, skip_flags}; }
Range allChanged() const { return all(SKIP_UNCHANGED); }
Range allUnchanged() const { return all(SKIP_CHANGED); }
Range allBuiltin() const { return all(SKIP_CUSTOM); }
Range allCustom() const { return all(SKIP_BUILTIN); }
Iterator begin() const { return allChanged().begin(); }
Iterator end() const { return allChanged().end(); }

Some files were not shown because too many files have changed in this diff Show More