@@ -2673,10 +2673,253 @@ INSERT INTO t1 VALUES('aa');
2673
2673
SET column_compression_threshold=DEFAULT;
2674
2674
DROP TABLE t1;
2675
2675
#
2676
- # End of 10.3 tests
2676
+ # MDEV-31724 Compressed varchar values lost on joins when sorting on columns from joined table(s)
2677
+ #
2678
+ CREATE TABLE t1 (
2679
+ id int(10) unsigned not null,
2680
+ txt varchar(5000) COMPRESSED NOT NULL DEFAULT '',
2681
+ PRIMARY KEY (id)
2682
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin;
2683
+ CREATE TABLE t2 (
2684
+ id int(10) unsigned not null,
2685
+ n1 bigint(20) NOT NULL,
2686
+ n2 bigint(20) NOT NULL,
2687
+ n3 bigint(20) NOT NULL,
2688
+ PRIMARY KEY (id)
2689
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin;
2690
+ INSERT INTO t1 VALUES
2691
+ (1, 'short string < 100 chars'),
2692
+ (2, 'long string = 99 chars '),
2693
+ (3, 'long string = 100 chars !'),
2694
+ (4, 'long string = 101 chars !');
2695
+ INSERT INTO t2 VALUES
2696
+ (1, 24, 1, 1),
2697
+ (2, 99, 2, 2),
2698
+ (3, 100, 3, 3),
2699
+ (4, 101, 4, 4);
2700
+ SELECT txt, v.* FROM t1 LEFT JOIN t2 v ON t1.id = v.id;
2701
+ txt id n1 n2 n3
2702
+ short string < 100 chars 1 24 1 1
2703
+ long string = 99 chars 2 99 2 2
2704
+ long string = 100 chars ! 3 100 3 3
2705
+ long string = 101 chars ! 4 101 4 4
2706
+ SELECT txt, v.* FROM t1 LEFT JOIN t2 v ON t1.id = v.id ORDER BY v.n1;
2707
+ txt id n1 n2 n3
2708
+ short string < 100 chars 1 24 1 1
2709
+ long string = 99 chars 2 99 2 2
2710
+ long string = 100 chars ! 3 100 3 3
2711
+ long string = 101 chars ! 4 101 4 4
2712
+ SELECT txt, v.* FROM t1 JOIN t2 v ON t1.id = v.id;
2713
+ txt id n1 n2 n3
2714
+ short string < 100 chars 1 24 1 1
2715
+ long string = 99 chars 2 99 2 2
2716
+ long string = 100 chars ! 3 100 3 3
2717
+ long string = 101 chars ! 4 101 4 4
2718
+ SELECT txt, v.* FROM t1 JOIN t2 v ON t1.id = v.id ORDER BY v.n1;
2719
+ txt id n1 n2 n3
2720
+ short string < 100 chars 1 24 1 1
2721
+ long string = 99 chars 2 99 2 2
2722
+ long string = 100 chars ! 3 100 3 3
2723
+ long string = 101 chars ! 4 101 4 4
2724
+ DROP TABLE t1, t2;
2725
+ CREATE OR REPLACE TABLE t1 (
2726
+ id INT NOT NULL PRIMARY KEY,
2727
+ txt varchar(5000) COMPRESSED NOT NULL DEFAULT ''
2728
+ ) CHARSET=utf8mb3;
2729
+ INSERT INTO t1 VALUES
2730
+ (1, REPEAT('a', 10)),
2731
+ (2, REPEAT('b', 99)),
2732
+ (3, REPEAT('c', 100)),
2733
+ (4, REPEAT('d', 121));
2734
+ SELECT txt, sysdate(6) FROM t1 ORDER BY 2;
2735
+ txt sysdate(6)
2736
+ aaaaaaaaaa <sysdate>
2737
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb <sysdate>
2738
+ cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc <sysdate>
2739
+ ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd <sysdate>
2740
+ DROP TABLE t1;
2741
+ CREATE FUNCTION f1(imax INT, jmax INT) RETURNS TEXT
2742
+ BEGIN
2743
+ DECLARE res TEXT DEFAULT 'x';
2744
+ FOR i IN 0..imax
2745
+ DO
2746
+ FOR j IN 0..jmax
2747
+ DO
2748
+ SET res=CONCAT(res, ' ', i, ' ', j);
2749
+ END FOR;
2750
+ END FOR;
2751
+ RETURN res;
2752
+ END;
2753
+ $$
2754
+ SET @@column_compression_threshold=32;
2755
+ # VARCHAR1, 8bit, truncation
2756
+ CREATE TABLE t1 (a VARCHAR(254) COMPRESSED CHARACTER SET latin1);
2757
+ INSERT INTO t1 VALUES (f1(6,6));
2758
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2759
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2760
+ 197 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 6 6 0 6 1 6 2 6 3 6 4 6 5 6 6
2761
+ FLUSH STATUS;
2762
+ ALTER IGNORE TABLE t1 MODIFY a VARCHAR(4) COMPRESSED CHARACTER SET latin1;
2763
+ Warnings:
2764
+ Warning 1265 Data truncated for column 'a' at row 1
2765
+ SHOW STATUS LIKE 'Column%compressions';
2766
+ Variable_name Value
2767
+ Column_compressions 0
2768
+ Column_decompressions 1
2769
+ SELECT LENGTH(a), a FROM t1;
2770
+ LENGTH(a) a
2771
+ 4 x 0
2772
+ DROP TABLE t1;
2773
+ CREATE TABLE t1 (a VARCHAR(254) COMPRESSED CHARACTER SET latin1);
2774
+ INSERT INTO t1 VALUES (REPEAT('a',254));
2775
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2776
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2777
+ 254 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
2778
+ FLUSH STATUS;
2779
+ ALTER IGNORE TABLE t1 MODIFY a VARCHAR(4) COMPRESSED CHARACTER SET latin1;
2780
+ Warnings:
2781
+ Warning 1265 Data truncated for column 'a' at row 1
2782
+ SHOW STATUS LIKE 'Column%compressions';
2783
+ Variable_name Value
2784
+ Column_compressions 0
2785
+ Column_decompressions 1
2786
+ SELECT LENGTH(a), a FROM t1;
2787
+ LENGTH(a) a
2788
+ 4 aaaa
2789
+ DROP TABLE t1;
2790
+ # VARCHAR1, 8bit, no truncation
2791
+ CREATE TABLE t1 (a VARCHAR(250) COMPRESSED CHARACTER SET latin1);
2792
+ INSERT INTO t1 VALUES (f1(6,6));
2793
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2794
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2795
+ 197 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 6 6 0 6 1 6 2 6 3 6 4 6 5 6 6
2796
+ FLUSH STATUS;
2797
+ ALTER IGNORE TABLE t1 MODIFY a VARCHAR(254) COMPRESSED CHARACTER SET latin1;
2798
+ SHOW STATUS LIKE 'Column%compressions';
2799
+ Variable_name Value
2800
+ Column_compressions 0
2801
+ Column_decompressions 0
2802
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2803
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2804
+ 197 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 6 6 0 6 1 6 2 6 3 6 4 6 5 6 6
2805
+ DROP TABLE t1;
2806
+ # VARCHAR2, 8bit, truncation
2807
+ CREATE TABLE t1 (a VARCHAR(32000) COMPRESSED CHARACTER SET latin1);
2808
+ INSERT INTO t1 VALUES (f1(31,31));
2809
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2810
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2811
+ 5505 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 31 27 31 28 31 29 31 30 31 31
2812
+ FLUSH STATUS;
2813
+ ALTER IGNORE TABLE t1 MODIFY a VARCHAR(256) COMPRESSED CHARACTER SET latin1;
2814
+ Warnings:
2815
+ Warning 1265 Data truncated for column 'a' at row 1
2816
+ SHOW STATUS LIKE 'Column%compressions';
2817
+ Variable_name Value
2818
+ Column_compressions 1
2819
+ Column_decompressions 1
2820
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2821
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2822
+ 256 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 1 17 1 18 1 19 1 20 1 21 1 22
2823
+ DROP TABLE t1;
2824
+ # VARCHAR2, 8bit, no truncation
2825
+ CREATE TABLE t1 (a VARCHAR(32000) COMPRESSED CHARACTER SET latin1);
2826
+ INSERT INTO t1 VALUES (f1(31,31));
2827
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a, 30) FROM t1;
2828
+ LENGTH(a) LEFT(a,30) RIGHT(a, 30)
2829
+ 5505 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 31 27 31 28 31 29 31 30 31 31
2830
+ FLUSH STATUS;
2831
+ ALTER IGNORE TABLE t1 MODIFY a VARCHAR(32001) COMPRESSED CHARACTER SET latin1;
2832
+ SHOW STATUS LIKE 'Column%compressions';
2833
+ Variable_name Value
2834
+ Column_compressions 0
2835
+ Column_decompressions 0
2836
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a, 30) FROM t1;
2837
+ LENGTH(a) LEFT(a,30) RIGHT(a, 30)
2838
+ 5505 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 31 27 31 28 31 29 31 30 31 31
2839
+ DROP TABLE t1;
2840
+ # VARCHAR1, multi-byte, truncation
2841
+ CREATE TABLE t1 (a VARCHAR(80) COMPRESSED CHARACTER SET utf8mb3);
2842
+ INSERT INTO t1 VALUES (f1(3,3));
2843
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2844
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2845
+ 65 x 0 0 0 1 0 2 0 3 1 0 1 1 1 2 0 2 1 2 2 2 3 3 0 3 1 3 2 3 3
2846
+ FLUSH STATUS;
2847
+ ALTER IGNORE TABLE t1 MODIFY a VARCHAR(1) COMPRESSED CHARACTER SET utf8mb3;
2848
+ Warnings:
2849
+ Warning 1265 Data truncated for column 'a' at row 1
2850
+ SHOW STATUS LIKE 'Column%compressions';
2851
+ Variable_name Value
2852
+ Column_compressions 0
2853
+ Column_decompressions 1
2854
+ SELECT LENGTH(a), a FROM t1;
2855
+ LENGTH(a) a
2856
+ 1 x
2857
+ DROP TABLE t1;
2858
+ # VARCHAR1, multi-byte, no truncation
2859
+ CREATE TABLE t1 (a VARCHAR(80) COMPRESSED CHARACTER SET utf8mb3);
2860
+ INSERT INTO t1 VALUES (f1(3,3));
2861
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2862
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2863
+ 65 x 0 0 0 1 0 2 0 3 1 0 1 1 1 2 0 2 1 2 2 2 3 3 0 3 1 3 2 3 3
2864
+ FLUSH STATUS;
2865
+ ALTER IGNORE TABLE t1 MODIFY a VARCHAR(81) COMPRESSED CHARACTER SET utf8mb3;
2866
+ SHOW STATUS LIKE 'Column%compressions';
2867
+ Variable_name Value
2868
+ Column_compressions 0
2869
+ Column_decompressions 0
2870
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2871
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2872
+ 65 x 0 0 0 1 0 2 0 3 1 0 1 1 1 2 0 2 1 2 2 2 3 3 0 3 1 3 2 3 3
2873
+ DROP TABLE t1;
2874
+ # VARCHAR2, multi-byte, truncation
2875
+ CREATE TABLE t1 (a VARCHAR(10000) COMPRESSED CHARACTER SET utf8mb3);
2876
+ INSERT INTO t1 VALUES (f1(31,31));
2877
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2878
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2879
+ 5505 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 31 27 31 28 31 29 31 30 31 31
2880
+ FLUSH STATUS;
2881
+ ALTER IGNORE TABLE t1 MODIFY a VARCHAR(256) COMPRESSED CHARACTER SET utf8mb3;
2882
+ Warnings:
2883
+ Warning 1265 Data truncated for column 'a' at row 1
2884
+ SHOW STATUS LIKE 'Column%compressions';
2885
+ Variable_name Value
2886
+ Column_compressions 1
2887
+ Column_decompressions 1
2888
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2889
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2890
+ 256 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 1 17 1 18 1 19 1 20 1 21 1 22
2891
+ DROP TABLE t1;
2892
+ # VARCHAR2, multi-byte, no truncation
2893
+ CREATE TABLE t1 (a VARCHAR(10000) COMPRESSED CHARACTER SET utf8mb3);
2894
+ INSERT INTO t1 VALUES (f1(31,31));
2895
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2896
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2897
+ 5505 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 31 27 31 28 31 29 31 30 31 31
2898
+ FLUSH STATUS;
2899
+ ALTER IGNORE TABLE t1 MODIFY a VARCHAR(10001) COMPRESSED CHARACTER SET utf8mb3;
2900
+ SHOW STATUS LIKE 'Column%compressions';
2901
+ Variable_name Value
2902
+ Column_compressions 0
2903
+ Column_decompressions 0
2904
+ SELECT LENGTH(a), LEFT(a,30), RIGHT(a,30) FROM t1;
2905
+ LENGTH(a) LEFT(a,30) RIGHT(a,30)
2906
+ 5505 x 0 0 0 1 0 2 0 3 0 4 0 5 0 6 31 27 31 28 31 29 31 30 31 31
2907
+ DROP TABLE t1;
2908
+ SET @@column_compression_threshold=DEFAULT;
2909
+ DROP FUNCTION f1;
2910
+ #
2911
+ # MDEV-24797 Column Compression - ERROR 1265 (01000): Data truncated for column
2677
2912
#
2913
+ CREATE TABLE t1 (a VARCHAR(500) COMPRESSED CHARACTER SET utf8mb3) ENGINE=MyISAM;
2914
+ INSERT INTO t1 SET a=REPEAT('x',127);
2915
+ ALTER TABLE t1 FORCE, ALGORITHM=COPY;
2916
+ DROP TABLE t1;
2917
+ CREATE TABLE t1 (a VARCHAR(500) COMPRESSED CHARACTER SET utf8mb3) ENGINE=InnoDB;
2918
+ INSERT INTO t1 SET a=REPEAT('x',127);
2919
+ ALTER TABLE t1 FORCE, ALGORITHM=COPY;
2920
+ DROP TABLE t1;
2678
2921
#
2679
- # Start of 10.5 tests
2922
+ # End of 10.4 tests
2680
2923
#
2681
2924
#
2682
2925
# MDEV-19727 Add Type_handler::Key_part_spec_init_ft
0 commit comments