ck_sql_action

通过位图存储、查询数据

将user_id通过位图存储
最新文档
Bitmap Functions | ClickHouse Docs https://clickhouse.com/docs/en/sql-reference/functions/bitmap-functions#bitmap_functions-bitmapbuild


SELECT bitmapToArray(
subBitmap(
bitmapBuild([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,100,200,500])
, toUInt32(2), toUInt32(10)
)
) AS res;

历史版本方法名
-- rename bitmapSubsetOffsetLimit to subBitmap and modify the rb_offset_… · ClickHouse/ClickHouse@3dcff21 · GitHub https://github.com/ClickHouse/ClickHouse/commit/3dcff2124cef5e9af8a0b13a494bdef8b2ad4d7e
-- Merge pull request #7525 from godfreyd/en-docs/CLICKHOUSEDOCS-426-bit… · ClickHouse/ClickHouse@1c9b444 · GitHub https://github.com/ClickHouse/ClickHouse/commit/1c9b444e78d440788432cb2b2790d69b45ff5108

- `range_start` – The subset starting point. Type: [UInt32](../../data_types/int_uint.md).
- `cardinality_limit` – The subset cardinality upper limit. Type: [UInt32](../../data_types/int_uint.md).


SELECT bitmapToArray(
bitmapSubsetLimit(
bitmapBuild([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,100,200,500])
, toUInt32(2), toUInt32(10)
)
) AS res;


SELECT *
FROM system.build_options
SELECT *
FROM system.build_options

SELECT version();



DROP TABLE IF EXISTS test_db.tmp_bitmap_table;
-- bm 存储 bitMap,类型为UInt64
CREATE TABLE test_db.tmp_bitmap_table
(
    id UInt32,
    bm AggregateFunction(groupBitmap,Int64)
)
ENGINE = Memory();

-- 插入user_id,位图存储
insert into test_db.tmp_bitmap_table

select 2,groupBitmapState(id) from test_db.app_user where app_id=123

select count(*) from test_db.app_user where app_id=123
select groupBitmap(id) from test_db.app_user where app_id=123
;

select * from test_db.tmp_bitmap_table;

分页查询
select 1,
 bitmapToArray(
bitmapSubsetLimit(
bm, toUInt32(0), toUInt32(10)
)
)
from test_db.tmp_bitmap_table

union all

select 2,
 bitmapToArray(
bitmapSubsetLimit(
bm, toUInt32(789), toUInt32(9)
)
)
from test_db.tmp_bitmap_table;

返回的是user_id的列表
但发现上边的查询返回的第一个元素都为789,偏移量不生效?
select min(id) from test_db.app_user where app_id=123
发现最小值为789



 

 

 

查看clickhouse 版本号 构建信息

SELECT *
FROM system.build_options

SELECT *
FROM system.build_options

VERSION_FULL	ClickHouse 23.9.2.47608
VERSION_DESCRIBE	v23.9.2.47608-stable
VERSION_INTEGER	23009002
SYSTEM	Linux
VERSION_GITHASH	5dcfa636185dc09dc2c477b58fc439b0aa1b4f29
VERSION_REVISION	54479
BUILD_TYPE	RelWithDebInfo
SYSTEM_PROCESSOR	x86_64
CMAKE_VERSION	3.27.7
C_COMPILER	/usr/bin/clang-17
C_COMPILER_VERSION	17.0.6
CXX_COMPILER	/usr/bin/clang++-17
CXX_COMPILER_VERSION	17.0.6
C_FLAGS	--gcc-toolchain=./cmake/linux/../../contrib/sysroot/linux-x86_64 -fdiagnostics-color=always -Xclang -fuse-ctor-homing -Wno-enum-constexpr-conversion -gdwarf-aranges -pipe -mssse3 -msse4.1 -msse4.2 -mpclmul -mpopcnt -fasynchronous-unwind-tables -ffile-prefix-map=.=. -ftime-trace -falign-functions=32 -mbranches-within-32B-boundaries -fdiagnostics-absolute-paths -Wframe-larger-than=65536 -Weverything -Wpedantic -Wno-zero-length-array -Wno-c++98-compat-pedantic -Wno-c++98-compat -Wno-c++20-compat -Wno-sign-conversion -Wno-implicit-int-conversion -Wno-implicit-int-float-conversion -Wno-ctad-maybe-unsupported -Wno-disabled-macro-expansion -Wno-documentation-unknown-command -Wno-double-promotion -Wno-exit-time-destructors -Wno-float-equal -Wno-global-constructors -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-padded -Wno-switch-enum -Wno-undefined-func-template -Wno-unused-template -Wno-vla -Wno-weak-template-vtables -Wno-weak-vtables -Wno-thread-safety-negative -Wno-enum-constexpr-conversion -Wno-unsafe-buffer-usage -O2 -g -DNDEBUG -O3 -g -gdwarf-4 -flto=thin -fwhole-program-vtables -fno-pie
CXX_FLAGS	--gcc-toolchain=./cmake/linux/../../contrib/sysroot/linux-x86_64 -fdiagnostics-color=always -Xclang -fuse-ctor-homing -Wno-enum-constexpr-conversion -fsized-deallocation -gdwarf-aranges -pipe -mssse3 -msse4.1 -msse4.2 -mpclmul -mpopcnt -fasynchronous-unwind-tables -ffile-prefix-map=.=. -ftime-trace -falign-functions=32 -mbranches-within-32B-boundaries -fdiagnostics-absolute-paths -fstrict-vtable-pointers -Wall -Wextra -Wframe-larger-than=65536 -Weverything -Wpedantic -Wno-zero-length-array -Wno-c++98-compat-pedantic -Wno-c++98-compat -Wno-c++20-compat -Wno-sign-conversion -Wno-implicit-int-conversion -Wno-implicit-int-float-conversion -Wno-ctad-maybe-unsupported -Wno-disabled-macro-expansion -Wno-documentation-unknown-command -Wno-double-promotion -Wno-exit-time-destructors -Wno-float-equal -Wno-global-constructors -Wno-missing-prototypes -Wno-missing-variable-declarations -Wno-padded -Wno-switch-enum -Wno-undefined-func-template -Wno-unused-template -Wno-vla -Wno-weak-template-vtables -Wno-weak-vtables -Wno-thread-safety-negative -Wno-enum-constexpr-conversion -Wno-unsafe-buffer-usage -O2 -g -DNDEBUG -O3 -g -gdwarf-4 -flto=thin -fwhole-program-vtables -fno-pie
LINK_FLAGS	--gcc-toolchain=./cmake/linux/../../contrib/sysroot/linux-x86_64 --ld-path=/usr/bin/ld.lld-17 -Wl,--no-export-dynamic -Wl,--gdb-index -Wl,--build-id=sha1 -no-pie -Wl,-no-pie -flto=thin -fwhole-program-vtables
BUILD_COMPILE_DEFINITIONS	
USE_EMBEDDED_COMPILER	1
USE_GLIBC_COMPATIBILITY	ON
USE_JEMALLOC	ON
USE_ICU	1
USE_H3	1
USE_MYSQL	1
USE_RDKAFKA	1
USE_CAPNP	1
USE_BASE64	1
USE_HDFS	1
USE_SNAPPY	1
USE_PARQUET	1
USE_PROTOBUF	1
USE_BROTLI	1
USE_SSL	1
OPENSSL_VERSION	1.1.1g
OPENSSL_IS_BORING_SSL	1
USE_VECTORSCAN	ON
USE_SIMDJSON	1
USE_ODBC	1
USE_GRPC	1
USE_LDAP	1
TZDATA_VERSION	2023c
USE_KRB5	1
USE_FILELOG	1
USE_BZIP2	1
USE_AMQPCPP	1
USE_ROCKSDB	1
USE_NURAFT	1
USE_NLP	1
USE_LIBURING	1
USE_SQLITE	1
USE_LIBPQXX	1
USE_AZURE_BLOB_STORAGE	1
USE_AWS_S3	1
USE_CASSANDRA	1
USE_YAML_CPP	1
USE_SENTRY	1
USE_DATASKETCHES	1
USE_AVRO	1
USE_ARROW	1
USE_ORC	1
USE_MSGPACK	1
USE_QPL	ON
GIT_HASH	5dcfa636185dc09dc2c477b58fc439b0aa1b4f29
GIT_BRANCH	release/2023-10-12
GIT_DATE	2023-12-13 11:08:55 +0000
GIT_COMMIT_SUBJECT	Merge pull request #4747 from ClickHouse/backport/release/2023-10-12/57743

 

 

 

SELECT version();

 

How to check your ClickHouse version https://www.propeldata.com/blog/how-to-check-your-clickhouse-version

 

 

 

 

 

 

 

 

posted @ 2023-02-17 11:28  papering  阅读(487)  评论(0编辑  收藏  举报