Db2
VARCHAR / VARGRAPHIC 列的分佈統計資訊?
似乎只有前 n 個字元用作 varchar/vargraphic 列的 colvalue。從我下面的測試來看,它似乎是 33/16。長度是否記錄在某處?我試圖搜尋文件,但找不到任何東西(可能是搜尋錯誤的東西)
簡單的測試案例:
DROP TABLE LEJO0004.T; CREATE TABLE LEJO0004.T ( ID BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY ( START WITH 1 INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 NO CYCLE CACHE 20 NO ORDER ), TCOL_C VARCHAR(64) NOT NULL, TCOL_G VARGRAPHIC(64) NOT NULL ); insert into LEJO0004.T (tcol_c, tcol_g) with n100 (n) as ( values 0 union all select n+1 from n100 where n<100 ) , n10 (n) as ( values 0 union all select n+1 from n10 where n<10 ) , n1 (n) as ( values 0 ) select 'commons.domain.regel.avbrottsregel' , 'commons.domain.regel.avbrottsregel' from n100 union all select 'commons.domain.regel.grupp.overfors.nya.endast.som.merit' , 'commons.domain.regel.grupp.overfors.nya.endast.som.merit' from n10 union all select 'commons.domain.regel.ingar.i.grupp.overfors.till.nya' , 'commons.domain.regel.ingar.i.grupp.overfors.till.nya' from n1; runstats on table lejo0004.T with distribution on all columns; select cast(colname as varchar(15)) , type , seqno , cast(colvalue as varchar(40)) , valcount from sysstat.COLDIST where tabschema = 'LEJO0004' and tabname = 'T' and colname in ('TCOL_C', 'TCOL_G') and colvalue is not null and type = 'F' order by type, colname, seqno;
結果是:
TCOL_C F 1 'commons.domain.regel.avbrottsrege' 101 TCOL_C F 2 'commons.domain.regel.grupp.overfo' 11 TCOL_G F 1 g'commons.domain.r' 113
Q似乎是一樣的
values char_length(g'commons.domain.r' using codeunits32) 16 values char_length('commons.domain.regel.avbrottsrege' using codeunits32) 33
測試:
db2level DB21085I This instance or install (instance name, where applicable: "lejo0004") uses "64" bits and DB2 code release "SQL11050" with level identifier "0601010F". Informational tokens are "DB2 v11.5.0.0", "s1906101300", "DYN1906101300AMD64", and Fix Pack "0". Product is installed at "/home/lejo0004/sqllib".
它是“部分記錄”/“沒有真正記錄”的 AFAIK。更具體地說,有 APAR:
IT13369:在公共前綴大於 32 字節的字元串列上收集分佈統計資訊時的次優查詢性能
提到它。我假設您真正關心的是查詢的基數估計,該查詢在具有公共前綴的列上具有謂詞,在這種情況下,您可以嘗試使用它的解決方法(即不收集該列的分佈統計資訊)