alter_distribution_policy_optimizer.out 33.3 KB
Newer Older
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
-- ALTER TABLE ... SET DISTRIBUTED BY
-- This is the main interface for system expansion
\set DATA values(1, 2), (2, 3), (3, 4)
-- Basic sanity tests
set optimizer_disable_missing_stats_collection = on;
create table atsdb (i int, j text) distributed by (i);
insert into atsdb :DATA;
-- should fail
alter table atsdb set distributed by ();
ERROR:  syntax error at or near ")"
LINE 1: alter table atsdb set distributed by ();
                                              ^
alter table atsdb set distributed by (m);
ERROR:  column "m" of relation "atsdb" does not exist
alter table atsdb set distributed by (i, i);
ERROR:  distribution policy must be a unique set of columns
HINT:  Column "i" appears more than once
alter table atsdb set distributed by (i, m);
ERROR:  column "m" of relation "atsdb" does not exist
alter table atsdb set distributed by (i);
WARNING:  distribution policy of relation "atsdb" already set to (i)
HINT:  Use ALTER TABLE "atsdb" SET WITH (REORGANIZE=TRUE) DISTRIBUTED BY (i) to force redistribution
-- should work
alter table atsdb set distributed randomly;
select localoid::regclass, attrnums from gp_distribution_policy where localoid = 'atsdb'::regclass;
 localoid | attrnums 
----------+----------
 atsdb    | 
(1 row)

-- not possible to correctly verify random distribution
alter table atsdb set distributed by (j);
select localoid::regclass, attrnums from gp_distribution_policy where localoid = 'atsdb'::regclass;
 localoid | attrnums 
----------+----------
 atsdb    | {2}
(1 row)

-- verify that the data is correctly redistributed by building a fresh 
-- table with the same policy
create table ats_test (i int, j text) distributed by (j);
insert into ats_test :DATA;
select gp_segment_id, * from ats_test except
select gp_segment_id, * from atsdb;
 gp_segment_id | i | j 
---------------+---+---
(0 rows)

drop table ats_test;
alter table atsdb set distributed by (i, j);
select localoid::regclass, attrnums from gp_distribution_policy where localoid = 'atsdb'::regclass;
 localoid | attrnums 
----------+----------
 atsdb    | {1,2}
(1 row)

-- verify
create table ats_test (i int, j text) distributed by (i, j);
insert into ats_test :DATA;
select gp_segment_id, * from ats_test except
select gp_segment_id, * from atsdb;
 gp_segment_id | i | j 
---------------+---+---
(0 rows)

drop table ats_test;
alter table atsdb set distributed by (j, i);
select localoid::regclass, attrnums from gp_distribution_policy where localoid = 'atsdb'::regclass;
 localoid | attrnums 
----------+----------
 atsdb    | {2,1}
(1 row)

-- verify
create table ats_test (i int, j text) distributed by (j, i);
insert into ats_test :DATA;
select gp_segment_id, * from ats_test except
select gp_segment_id, * from atsdb;
 gp_segment_id | i | j 
---------------+---+---
(0 rows)

drop table ats_test;
-- Now make sure indexes work.
create index atsdb_i_idx on atsdb(i);
set enable_seqscan to off;
explain select * from atsdb where i = 1;
                                  QUERY PLAN                                   
-------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..1.01 rows=1 width=6)
   ->  Index Scan using atsdb_i_idx on atsdb  (cost=0.00..0.01 rows=1 width=6)
         Index Cond: i = 1
 Settings:  enable_seqscan=off; optimizer=on
(4 rows)

select * from atsdb where i = 1;
 i | j 
---+---
 1 | 2
(1 row)

alter table atsdb set distributed by (i);
explain select * from atsdb where i = 1;
                                  QUERY PLAN                                   
-------------------------------------------------------------------------------
 Gather Motion 3:1  (slice1; segments: 3)  (cost=0.00..1.01 rows=1 width=6)
   ->  Index Scan using atsdb_i_idx on atsdb  (cost=0.00..0.01 rows=1 width=6)
         Index Cond: i = 1
 Settings:  enable_seqscan=off; optimizer=on
(4 rows)

select * from atsdb where i = 1;
 i | j 
---+---
 1 | 2
(1 row)

drop table atsdb;
-- Now try AO
120
create table atsdb_ao (i int, j text) with (appendonly=true) distributed by (i);
121 122 123
insert into atsdb_ao select i, (i+1)::text from generate_series(1, 100) i;
insert into atsdb_ao select i, (i+1)::text from generate_series(1, 100) i;
-- check that we're an AO table
124 125 126 127 128
select count(*) from pg_appendonly where relid='atsdb_ao'::regclass;
 count
-------
     1
(1 row)
129 130 131 132 133 134 135 136 137

select count(*) from atsdb_ao;
 count 
-------
   200
(1 row)

alter table atsdb_ao set distributed by (j);
-- Still AO?
138 139 140 141 142
select count(*) from pg_appendonly where relid='atsdb_ao'::regclass;
 count
-------
     1
(1 row)
143 144 145 146 147 148 149

select count(*) from atsdb_ao;
 count 
-------
   200
(1 row)

150 151 152 153 154 155 156 157 158 159
-- check alter, vacuum analyze, and then alter
delete from atsdb_ao where i = any(array(select generate_series(1,90)));
vacuum analyze atsdb_ao;
alter table atsdb_ao set distributed randomly;
select count(*) from atsdb_ao;
 count
-------
    20
(1 row)

160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
drop table atsdb_ao;
-- Check divergent distribution policies for partitioning.
create table atsdb (i int, j int, k int) distributed by (i) partition by range(k)
(start(1) end(4) every(1));
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_1" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_2" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_3" for table "atsdb"
alter table atsdb_1_prt_2 set distributed by (j);
ERROR:  cannot SET DISTRIBUTED BY for atsdb_1_prt_2
HINT:  Leaf distribution policy must be random or match that of the entire partitioned table.
alter table atsdb_1_prt_3 set distributed randomly;
-- test COPY
copy atsdb from stdin delimiter '|';
select count(*) from atsdb;
 count 
-------
    18
(1 row)

-- compare distribution: we create a table, identical to the partitioned table,
-- and compare how the tuples have been distributed.
create table atsdb_1 (like atsdb_1_prt_1) distributed by (i);
copy atsdb_1 from stdin delimiter '|';
select gp_segment_id, * from atsdb where k = 1 except 
select gp_segment_id, * from atsdb_1;
 gp_segment_id | i | j | k 
---------------+---+---+---
(0 rows)

create table atsdb_2 (like atsdb_1_prt_2) distributed by (i);
copy atsdb_2 from stdin delimiter '|';
select gp_segment_id, * from atsdb where k = 2 except
select gp_segment_id, * from atsdb_2;
 gp_segment_id | i | j | k 
---------------+---+---+---
(0 rows)

-- Can't test randomly distributed
-- Can't test INSERT (yet)
drop table atsdb, atsdb_1, atsdb_2;
-- Can't redistribute system catalogs
alter table pg_class set distributed by (relname);
ERROR:  permission denied: "pg_class" is a system catalog
alter table pg_class set with(appendonly = true);
ERROR:  permission denied: "pg_class" is a system catalog
-- MPP-7770: allow testing of changing storage for now
set gp_setwith_alter_storage = true;
alter table pg_class set with(appendonly = true);
ERROR:  permission denied: "pg_class" is a system catalog
-- WITH clause
create table atsdb (i int, j text) distributed by (j);
insert into atsdb select i, i::text from generate_series(1, 10) i;
alter table atsdb set with(appendonly = true);
select relname, segrelid != 0, reloptions from pg_class, pg_appendonly where pg_class.oid =
'atsdb'::regclass and relid = pg_class.oid;
 relname | ?column? |    reloptions     
---------+----------+-------------------
 atsdb   | t        | {appendonly=true}
(1 row)

select * from atsdb;
 i  | j  
----+----
  1 | 1
  4 | 4
  7 | 7
  3 | 3
  6 | 6
  9 | 9
 10 | 10
  2 | 2
  5 | 5
  8 | 8
(10 rows)

drop table atsdb;
create view distcheck as select relname as rel, attname from
gp_distribution_policy g, pg_attribute p, pg_class c
where g.localoid = p.attrelid and attnum = any(g.attrnums) and
c.oid = p.attrelid;
-- dropped columns
create table atsdb (i int, j int, t text, n numeric) distributed by (j);
insert into atsdb select i, i+1, i+2, i+3 from generate_series(1, 100) i;
alter table atsdb drop column i;
select * from atsdb;
  j  |  t  |  n  
-----+-----+-----
   3 | 4   |   5
   4 | 5   |   6
   5 | 6   |   7
   6 | 7   |   8
   7 | 8   |   9
  18 | 19  |  20
  19 | 20  |  21
  20 | 21  |  22
  21 | 22  |  23
  22 | 23  |  24
  38 | 39  |  40
  39 | 40  |  41
  40 | 41  |  42
  41 | 42  |  43
  42 | 43  |  44
  53 | 54  |  55
  54 | 55  |  56
  55 | 56  |  57
  56 | 57  |  58
  57 | 58  |  59
  73 | 74  |  75
  74 | 75  |  76
  75 | 76  |  77
  76 | 77  |  78
  77 | 78  |  79
  87 | 88  |  89
  88 | 89  |  90
  89 | 90  |  91
  90 | 91  |  92
  91 | 92  |  93
  96 | 97  |  98
  97 | 98  |  99
   8 | 9   |  10
   9 | 10  |  11
  10 | 11  |  12
  11 | 12  |  13
  12 | 13  |  14
  23 | 24  |  25
  24 | 25  |  26
  25 | 26  |  27
  26 | 27  |  28
  27 | 28  |  29
  32 | 33  |  34
  43 | 44  |  45
  44 | 45  |  46
  45 | 46  |  47
  46 | 47  |  48
  47 | 48  |  49
  58 | 59  |  60
  59 | 60  |  61
  60 | 61  |  62
  61 | 62  |  63
  62 | 63  |  64
  64 | 65  |  66
  65 | 66  |  67
  66 | 67  |  68
  67 | 68  |  69
  78 | 79  |  80
  79 | 80  |  81
  80 | 81  |  82
  81 | 82  |  83
  82 | 83  |  84
  92 | 93  |  94
  93 | 94  |  95
  94 | 95  |  96
  95 | 96  |  97
  98 | 99  | 100
  99 | 100 | 101
 100 | 101 | 102
 101 | 102 | 103
   2 | 3   |   4
  13 | 14  |  15
  14 | 15  |  16
  15 | 16  |  17
  16 | 17  |  18
  17 | 18  |  19
  28 | 29  |  30
  29 | 30  |  31
  30 | 31  |  32
  31 | 32  |  33
  33 | 34  |  35
  34 | 35  |  36
  35 | 36  |  37
  36 | 37  |  38
  37 | 38  |  39
  48 | 49  |  50
  49 | 50  |  51
  50 | 51  |  52
  51 | 52  |  53
  52 | 53  |  54
  63 | 64  |  65
  68 | 69  |  70
  69 | 70  |  71
  70 | 71  |  72
  71 | 72  |  73
  72 | 73  |  74
  83 | 84  |  85
  84 | 85  |  86
  85 | 86  |  87
  86 | 87  |  88
(100 rows)

alter table atsdb set distributed by (t);
select * from distcheck where rel = 'atsdb';
  rel  | attname 
-------+---------
 atsdb | t
(1 row)

alter table atsdb drop column n;
alter table atsdb set with(appendonly = true, compresslevel = 3);
select relname, segrelid != 0, reloptions from pg_class, pg_appendonly where pg_class.oid = 
'atsdb'::regclass and relid = pg_class.oid;
 relname | ?column? |            reloptions             
---------+----------+-----------------------------------
 atsdb   | t        | {appendonly=true,compresslevel=3}
(1 row)

select * from distcheck where rel = 'atsdb';
  rel  | attname 
-------+---------
 atsdb | t
(1 row)

select * from atsdb;
  j  |  t  
-----+-----
   3 | 4
   6 | 7
  18 | 19
  20 | 21
  42 | 43
  53 | 54
  73 | 74
  76 | 77
  77 | 78
  88 | 89
  90 | 91
  91 | 92
  12 | 13
  23 | 24
  26 | 27
  27 | 28
  43 | 44
  58 | 59
  60 | 61
  65 | 66
  82 | 83
  93 | 94
  99 | 100
  14 | 15
  15 | 16
  31 | 32
  33 | 34
  36 | 37
  37 | 38
  48 | 49
  52 | 53
  70 | 71
  84 | 85
  85 | 86
   4 | 5
   7 | 8
  21 | 22
  39 | 40
  56 | 57
  57 | 58
  75 | 76
  89 | 90
  96 | 97
  10 | 11
  11 | 12
  24 | 25
  44 | 45
  45 | 46
  61 | 62
  66 | 67
  67 | 68
  79 | 80
  98 | 99
  13 | 14
  17 | 18
  28 | 29
  30 | 31
  35 | 36
  50 | 51
  51 | 52
  63 | 64
  69 | 70
  72 | 73
  86 | 87
   5 | 6
  19 | 20
  22 | 23
  38 | 39
  40 | 41
  41 | 42
  54 | 55
  55 | 56
  74 | 75
  87 | 88
  97 | 98
   8 | 9
   9 | 10
  25 | 26
  32 | 33
  46 | 47
  47 | 48
  59 | 60
  62 | 63
  64 | 65
  78 | 79
  80 | 81
  81 | 82
  92 | 93
  94 | 95
  95 | 96
 100 | 101
 101 | 102
   2 | 3
  16 | 17
  29 | 30
  34 | 35
  49 | 50
  68 | 69
  71 | 72
  83 | 84
(100 rows)

alter table atsdb set distributed by (j);
select * from distcheck where rel = 'atsdb';
  rel  | attname 
-------+---------
 atsdb | j
(1 row)

select relname, segrelid != 0, reloptions from pg_class, pg_appendonly where pg_class.oid =
'atsdb'::regclass and relid = pg_class.oid;
 relname | ?column? |            reloptions             
---------+----------+-----------------------------------
 atsdb   | t        | {appendonly=true,compresslevel=3}
(1 row)

select * from atsdb;
  j  |  t  
-----+-----
  10 | 11
  11 | 12
  24 | 25
  44 | 45
  45 | 46
  61 | 62
  66 | 67
  67 | 68
  79 | 80
  98 | 99
  12 | 13
  23 | 24
  26 | 27
  27 | 28
  43 | 44
  58 | 59
  60 | 61
  65 | 66
  82 | 83
  93 | 94
  99 | 100
   8 | 9
   9 | 10
  25 | 26
  32 | 33
  46 | 47
  47 | 48
  59 | 60
  62 | 63
  64 | 65
  78 | 79
  80 | 81
  81 | 82
  92 | 93
  94 | 95
  95 | 96
 100 | 101
 101 | 102
   4 | 5
   7 | 8
  21 | 22
  39 | 40
  56 | 57
  57 | 58
  75 | 76
  89 | 90
  96 | 97
   3 | 4
   6 | 7
  18 | 19
  20 | 21
  42 | 43
  53 | 54
  73 | 74
  76 | 77
  77 | 78
  88 | 89
  90 | 91
  91 | 92
   5 | 6
  19 | 20
  22 | 23
  38 | 39
  40 | 41
  41 | 42
  54 | 55
  55 | 56
  74 | 75
  87 | 88
  97 | 98
  13 | 14
  17 | 18
  28 | 29
  30 | 31
  35 | 36
  50 | 51
  51 | 52
  63 | 64
  69 | 70
  72 | 73
  86 | 87
  14 | 15
  15 | 16
  31 | 32
  33 | 34
  36 | 37
  37 | 38
  48 | 49
  52 | 53
  70 | 71
  84 | 85
  85 | 86
   2 | 3
  16 | 17
  29 | 30
  34 | 35
  49 | 50
  68 | 69
  71 | 72
  83 | 84
(100 rows)

-- validate parameters
alter table atsdb set with (appendonly = ff);
ERROR:  invalid parameter value for "appendonly": "ff"
alter table atsdb set with (reorganize = true);
alter table atsdb set with (fgdfgef = asds);
ERROR:  unrecognized parameter "fgdfgef"
alter table atsdb set with(reorganize = true, reorganize = false) distributed
randomly;
ERROR:  "reorganize" specified more than once
drop table atsdb;
-- Check that we correctly cascade for partitioned tables
create table atsdb (i int, j int, k int) distributed by (i) partition by range(k)
(start(1) end(10) every(1));
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_1" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_2" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_3" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_4" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_5" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_6" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_7" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_8" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_9" for table "atsdb"
insert into atsdb select i+2, i+1, i from generate_series(1, 9) i;
select * from distcheck where rel like 'atsdb%';
      rel      | attname 
---------------+---------
 atsdb_1_prt_1 | i
 atsdb_1_prt_2 | i
 atsdb_1_prt_3 | i
 atsdb_1_prt_4 | i
 atsdb_1_prt_5 | i
 atsdb_1_prt_6 | i
 atsdb_1_prt_7 | i
 atsdb_1_prt_8 | i
 atsdb_1_prt_9 | i
 atsdb         | i
(10 rows)

alter table atsdb set distributed by (j);
select * from distcheck where rel like 'atsdb%';
      rel      | attname 
---------------+---------
 atsdb         | j
 atsdb_1_prt_1 | j
 atsdb_1_prt_2 | j
 atsdb_1_prt_3 | j
 atsdb_1_prt_4 | j
 atsdb_1_prt_5 | j
 atsdb_1_prt_6 | j
 atsdb_1_prt_7 | j
 atsdb_1_prt_8 | j
 atsdb_1_prt_9 | j
(10 rows)

select * from atsdb order by 1, 2, 3;
 i  | j  | k 
----+----+---
  3 |  2 | 1
  4 |  3 | 2
  5 |  4 | 3
  6 |  5 | 4
  7 |  6 | 5
  8 |  7 | 6
  9 |  8 | 7
 10 |  9 | 8
 11 | 10 | 9
(9 rows)

alter table atsdb set with(appendonly = true);
select relname, a.blocksize, compresslevel, compresstype, checksum from pg_class c, pg_appendonly a where 
relname  like 'atsdb%' and c.oid = a.relid order by 1;
    relname    | blocksize | compresslevel | compresstype | checksum 
---------------+-----------+---------------+--------------+----------
 atsdb         |     32768 |             0 |              | t
 atsdb_1_prt_1 |     32768 |             0 |              | t
 atsdb_1_prt_2 |     32768 |             0 |              | t
 atsdb_1_prt_3 |     32768 |             0 |              | t
 atsdb_1_prt_4 |     32768 |             0 |              | t
 atsdb_1_prt_5 |     32768 |             0 |              | t
 atsdb_1_prt_6 |     32768 |             0 |              | t
 atsdb_1_prt_7 |     32768 |             0 |              | t
 atsdb_1_prt_8 |     32768 |             0 |              | t
 atsdb_1_prt_9 |     32768 |             0 |              | t
(10 rows)

select * from atsdb order by 1, 2, 3;
 i  | j  | k 
----+----+---
  3 |  2 | 1
  4 |  3 | 2
  5 |  4 | 3
  6 |  5 | 4
  7 |  6 | 5
  8 |  7 | 6
  9 |  8 | 7
 10 |  9 | 8
 11 | 10 | 9
(9 rows)

insert into atsdb select i+2, i+1, i from generate_series(1, 9) i;
select * from atsdb order by 1, 2, 3;
 i  | j  | k 
----+----+---
  3 |  2 | 1
  3 |  2 | 1
  4 |  3 | 2
  4 |  3 | 2
  5 |  4 | 3
  5 |  4 | 3
  6 |  5 | 4
  6 |  5 | 4
  7 |  6 | 5
  7 |  6 | 5
  8 |  7 | 6
  8 |  7 | 6
  9 |  8 | 7
  9 |  8 | 7
 10 |  9 | 8
 10 |  9 | 8
 11 | 10 | 9
 11 | 10 | 9
(18 rows)

drop table atsdb;
drop view distcheck;
-- MPP-5452
-- Should succeed
create table atsdb (i int, k int) distributed by (i) partition by range(i) (start (1) end(10)
every(1));
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_1" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_2" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_3" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_4" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_5" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_6" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_7" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_8" for table "atsdb"
NOTICE:  CREATE TABLE will create partition "atsdb_1_prt_9" for table "atsdb"
alter table atsdb alter partition for(rank(5)) set distributed by (i);
NOTICE:  altering table "atsdb_1_prt_5" (partition for rank 5 of relation "atsdb")
WARNING:  distribution policy of relation "atsdb_1_prt_5" already set to (i)
HINT:  Use ALTER TABLE "atsdb_1_prt_5" SET WITH (REORGANIZE=TRUE) DISTRIBUTED BY (i) to force redistribution
alter table atsdb alter partition for(rank(5)) set distributed by (i);
NOTICE:  altering table "atsdb_1_prt_5" (partition for rank 5 of relation "atsdb")
WARNING:  distribution policy of relation "atsdb_1_prt_5" already set to (i)
HINT:  Use ALTER TABLE "atsdb_1_prt_5" SET WITH (REORGANIZE=TRUE) DISTRIBUTED BY (i) to force redistribution
alter table atsdb alter partition for(rank(5)) set distributed by (i);
NOTICE:  altering table "atsdb_1_prt_5" (partition for rank 5 of relation "atsdb")
WARNING:  distribution policy of relation "atsdb_1_prt_5" already set to (i)
HINT:  Use ALTER TABLE "atsdb_1_prt_5" SET WITH (REORGANIZE=TRUE) DISTRIBUTED BY (i) to force redistribution
drop table atsdb;
--MPP-5500
CREATE TABLE test_add_drop_rename_column_change_datatype(
 text_col text,
 bigint_col bigint,
 char_vary_col character varying(30),
 numeric_col numeric,
 int_col int4,
 float_col float4,
 int_array_col int[],
 drop_col numeric,
 before_rename_col int4,
 change_datatype_col numeric,
 a_ts_without timestamp without time zone,
 b_ts_with timestamp with time zone,
 date_column date) distributed randomly;
 
insert into test_add_drop_rename_column_change_datatype values ('0_zero', 0, '0_zero', 0, 0, 0, '{0}', 0, 0, 0, '2004-10-19 10:23:54', '2004-10-19 10:23:54+02', '1-1-2000');
insert into test_add_drop_rename_column_change_datatype values ('1_zero', 1, '1_zero', 1, 1, 1, '{1}', 1, 1, 1, '2005-10-19 10:23:54', '2005-10-19 10:23:54+02', '1-1-2001');
insert into test_add_drop_rename_column_change_datatype values ('2_zero', 2, '2_zero', 2, 2, 2, '{2}', 2, 2, 2, '2006-10-19 10:23:54', '2006-10-19 10:23:54+02', '1-1-2002');
 
ALTER TABLE test_add_drop_rename_column_change_datatype ADD COLUMN added_col character varying(30);
ALTER TABLE test_add_drop_rename_column_change_datatype DROP COLUMN drop_col ;
ALTER TABLE test_add_drop_rename_column_change_datatype RENAME COLUMN before_rename_col TO after_rename_col;
ALTER TABLE test_add_drop_rename_column_change_datatype ALTER COLUMN change_datatype_col TYPE int4;
alter table test_add_drop_rename_column_change_datatype set with(reorganize =
true) distributed randomly;
select * from test_add_drop_rename_column_change_datatype ;
 text_col | bigint_col | char_vary_col | numeric_col | int_col | float_col | int_array_col | after_rename_col | change_datatype_col |       a_ts_without       |          b_ts_with           | date_column | added_col 
----------+------------+---------------+-------------+---------+-----------+---------------+------------------+---------------------+--------------------------+------------------------------+-------------+-----------
 0_zero   |          0 | 0_zero        |           0 |       0 |         0 | {0}           |                0 |                   0 | Tue Oct 19 10:23:54 2004 | Tue Oct 19 01:23:54 2004 PDT | 01-01-2000  | 
 1_zero   |          1 | 1_zero        |           1 |       1 |         1 | {1}           |                1 |                   1 | Wed Oct 19 10:23:54 2005 | Wed Oct 19 01:23:54 2005 PDT | 01-01-2001  | 
 2_zero   |          2 | 2_zero        |           2 |       2 |         2 | {2}           |                2 |                   2 | Thu Oct 19 10:23:54 2006 | Thu Oct 19 01:23:54 2006 PDT | 01-01-2002  | 
(3 rows)

drop table test_add_drop_rename_column_change_datatype ;
-- MPP-5501
-- should run without error
create table atsdb with (appendonly=true) as select * from
generate_series(1,1000);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column(s) named 'generate_series' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
alter table only atsdb set with(reorganize=true) distributed by (generate_series);
select count(*) from atsdb;
 count 
-------
  1000
(1 row)

drop table atsdb;
-- MPP-5746
create table mpp5746 (c int[], t text);
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'c' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
insert into mpp5746 select array[i], i from generate_series(1, 100) i;
alter table mpp5746 set with (reorganize=true, appendonly = true);
select * from mpp5746 order by 1;
   c   |  t  
-------+-----
 {1}   | 1
 {2}   | 2
 {3}   | 3
 {4}   | 4
 {5}   | 5
 {6}   | 6
 {7}   | 7
 {8}   | 8
 {9}   | 9
 {10}  | 10
 {11}  | 11
 {12}  | 12
 {13}  | 13
 {14}  | 14
 {15}  | 15
 {16}  | 16
 {17}  | 17
 {18}  | 18
 {19}  | 19
 {20}  | 20
 {21}  | 21
 {22}  | 22
 {23}  | 23
 {24}  | 24
 {25}  | 25
 {26}  | 26
 {27}  | 27
 {28}  | 28
 {29}  | 29
 {30}  | 30
 {31}  | 31
 {32}  | 32
 {33}  | 33
 {34}  | 34
 {35}  | 35
 {36}  | 36
 {37}  | 37
 {38}  | 38
 {39}  | 39
 {40}  | 40
 {41}  | 41
 {42}  | 42
 {43}  | 43
 {44}  | 44
 {45}  | 45
 {46}  | 46
 {47}  | 47
 {48}  | 48
 {49}  | 49
 {50}  | 50
 {51}  | 51
 {52}  | 52
 {53}  | 53
 {54}  | 54
 {55}  | 55
 {56}  | 56
 {57}  | 57
 {58}  | 58
 {59}  | 59
 {60}  | 60
 {61}  | 61
 {62}  | 62
 {63}  | 63
 {64}  | 64
 {65}  | 65
 {66}  | 66
 {67}  | 67
 {68}  | 68
 {69}  | 69
 {70}  | 70
 {71}  | 71
 {72}  | 72
 {73}  | 73
 {74}  | 74
 {75}  | 75
 {76}  | 76
 {77}  | 77
 {78}  | 78
 {79}  | 79
 {80}  | 80
 {81}  | 81
 {82}  | 82
 {83}  | 83
 {84}  | 84
 {85}  | 85
 {86}  | 86
 {87}  | 87
 {88}  | 88
 {89}  | 89
 {90}  | 90
 {91}  | 91
 {92}  | 92
 {93}  | 93
 {94}  | 94
 {95}  | 95
 {96}  | 96
 {97}  | 97
 {98}  | 98
 {99}  | 99
 {100} | 100
(100 rows)

alter table mpp5746 drop column t;
select * from mpp5746 order by 1;
   c   
-------
 {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}
 {34}
 {35}
 {36}
 {37}
 {38}
 {39}
 {40}
 {41}
 {42}
 {43}
 {44}
 {45}
 {46}
 {47}
 {48}
 {49}
 {50}
 {51}
 {52}
 {53}
 {54}
 {55}
 {56}
 {57}
 {58}
 {59}
 {60}
 {61}
 {62}
 {63}
 {64}
 {65}
 {66}
 {67}
 {68}
 {69}
 {70}
 {71}
 {72}
 {73}
 {74}
 {75}
 {76}
 {77}
 {78}
 {79}
 {80}
 {81}
 {82}
 {83}
 {84}
 {85}
 {86}
 {87}
 {88}
 {89}
 {90}
 {91}
 {92}
 {93}
 {94}
 {95}
 {96}
 {97}
 {98}
 {99}
 {100}
(100 rows)

alter table mpp5746 set with (reorganize=true, appendonly = false);
select * from mpp5746 order by 1;
   c   
-------
 {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}
 {34}
 {35}
 {36}
 {37}
 {38}
 {39}
 {40}
 {41}
 {42}
 {43}
 {44}
 {45}
 {46}
 {47}
 {48}
 {49}
 {50}
 {51}
 {52}
 {53}
 {54}
 {55}
 {56}
 {57}
 {58}
 {59}
 {60}
 {61}
 {62}
 {63}
 {64}
 {65}
 {66}
 {67}
 {68}
 {69}
 {70}
 {71}
 {72}
 {73}
 {74}
 {75}
 {76}
 {77}
 {78}
 {79}
 {80}
 {81}
 {82}
 {83}
 {84}
 {85}
 {86}
 {87}
 {88}
 {89}
 {90}
 {91}
 {92}
 {93}
 {94}
 {95}
 {96}
 {97}
 {98}
 {99}
 {100}
(100 rows)

drop table mpp5746;
-- MPP-5738
create table mpp5738 (a int, b int, c int, d int)
partition by range(d) (start(1) end(10) inclusive every(1));
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
NOTICE:  CREATE TABLE will create partition "mpp5738_1_prt_1" for table "mpp5738"
NOTICE:  CREATE TABLE will create partition "mpp5738_1_prt_2" for table "mpp5738"
NOTICE:  CREATE TABLE will create partition "mpp5738_1_prt_3" for table "mpp5738"
NOTICE:  CREATE TABLE will create partition "mpp5738_1_prt_4" for table "mpp5738"
NOTICE:  CREATE TABLE will create partition "mpp5738_1_prt_5" for table "mpp5738"
NOTICE:  CREATE TABLE will create partition "mpp5738_1_prt_6" for table "mpp5738"
NOTICE:  CREATE TABLE will create partition "mpp5738_1_prt_7" for table "mpp5738"
NOTICE:  CREATE TABLE will create partition "mpp5738_1_prt_8" for table "mpp5738"
NOTICE:  CREATE TABLE will create partition "mpp5738_1_prt_9" for table "mpp5738"
insert into mpp5738 select i, i+1, i+2, i from generate_series(1, 10) i;
select * from mpp5738;
 a  | b  | c  | d  
----+----+----+----
  8 |  9 | 10 |  8
  9 | 10 | 11 |  9
 10 | 11 | 12 | 10
  1 |  2 |  3 |  1
  2 |  3 |  4 |  2
  3 |  4 |  5 |  3
  4 |  5 |  6 |  4
  5 |  6 |  7 |  5
  6 |  7 |  8 |  6
  7 |  8 |  9 |  7
(10 rows)

alter table mpp5738 alter partition for(rank(1)) set with (appendonly=true);
NOTICE:  altering table "mpp5738_1_prt_1" (partition for rank 1 of relation "mpp5738")
select * from mpp5738;
 a  | b  | c  | d  
----+----+----+----
  3 |  4 |  5 |  3
  4 |  5 |  6 |  4
  5 |  6 |  7 |  5
  6 |  7 |  8 |  6
  7 |  8 |  9 |  7
  1 |  2 |  3 |  1
  2 |  3 |  4 |  2
  8 |  9 | 10 |  8
  9 | 10 | 11 |  9
 10 | 11 | 12 | 10
(10 rows)

drop table mpp5738;
drop table if exists mpp5754;
NOTICE:  table "mpp5754" does not exist, skipping
CREATE TABLE mpp5754 (
             N_NATIONKEY INTEGER,
             N_NAME CHAR(25),
             N_REGIONKEY INTEGER,
             N_COMMENT VARCHAR(152)
             ) with (appendonly = true, checksum = true)
             distributed by (N_NATIONKEY);
copy mpp5754 from stdin with delimiter '|';
select * from mpp5754 order by n_nationkey;
 n_nationkey |          n_name           | n_regionkey |                      n_comment                      
-------------+---------------------------+-------------+-----------------------------------------------------
           0 | ALGERIA                   |           0 |  haggle. carefully final deposits detect slyly agai
(1 row)

alter table mpp5754 set distributed randomly;
select count(*) from mpp5754;
 count 
-------
     1
(1 row)

alter table mpp5754 set distributed by (n_nationkey);
select * from mpp5754 order by n_nationkey;
 n_nationkey |          n_name           | n_regionkey |                      n_comment                      
-------------+---------------------------+-------------+-----------------------------------------------------
           0 | ALGERIA                   |           0 |  haggle. carefully final deposits detect slyly agai
(1 row)

drop table mpp5754;
-- MPP-5918
create role atsdb;
NOTICE:  resource queue required -- using default resource queue "pg_default"
create table owner_test(i int, toast text) distributed randomly;
alter table owner_test owner to atsdb;
alter table owner_test set with (reorganize = true) distributed by (i);
-- verify, atsdb should own all three
select a.relname, 
       x.rolname as relowner, 
       y.rolname as toastowner,
	   z.rolname as toastidxowner
from pg_class a, pg_class b, pg_class c, 
     pg_authid x, pg_authid y, pg_authid z
where a.reltoastrelid = b.oid 
  and b.reltoastidxid=c.oid
  and a.relname='owner_test'
  and x.oid = a.relowner
  and y.oid = b.relowner
  and z.oid = c.relowner;
  relname   | relowner | toastowner | toastidxowner 
------------+----------+------------+---------------
 owner_test | atsdb    | atsdb      | atsdb
(1 row)

-- MPP-9663 - Check that the ownership is consistent on the segments as well
select a.relname, 
       x.rolname as relowner, 
       y.rolname as toastowner,
	   z.rolname as toastidxowner
from gp_dist_random('pg_class') a, 
	 gp_dist_random('pg_class') b, 
	 gp_dist_random('pg_class') c, 
     pg_authid x, pg_authid y, pg_authid z
where a.reltoastrelid=b.oid
  and b.reltoastidxid=c.oid
  and a.relname='owner_test'
  and x.oid = a.relowner
  and y.oid = b.relowner
  and z.oid = c.relowner
  and a.gp_segment_id = 0
  and b.gp_segment_id = 0
  and c.gp_segment_id = 0;
  relname   | relowner | toastowner | toastidxowner 
------------+----------+------------+---------------
 owner_test | atsdb    | atsdb      | atsdb
(1 row)

-- MPP-9663 - The code path is different when the table has dropped columns
alter table owner_test add column d text;
alter table owner_test drop column d;
alter table owner_test set with (reorganize = true) distributed by (i);
select a.relname, 
       x.rolname as relowner, 
       y.rolname as toastowner,
	   z.rolname as toastidxowner
from gp_dist_random('pg_class') a, 
	 gp_dist_random('pg_class') b, 
	 gp_dist_random('pg_class') c, 
     pg_authid x, pg_authid y, pg_authid z
where a.reltoastrelid=b.oid
  and b.reltoastidxid=c.oid
  and a.relname='owner_test'
  and x.oid = a.relowner
  and y.oid = b.relowner
  and z.oid = c.relowner
  and a.gp_segment_id = 0
  and b.gp_segment_id = 0
  and c.gp_segment_id = 0;
  relname   | relowner | toastowner | toastidxowner 
------------+----------+------------+---------------
 owner_test | atsdb    | atsdb      | atsdb
(1 row)

drop table owner_test;
drop role atsdb;
-- MPP-6332
create table abc (a int, b int, c int) distributed by (a);
Alter table abc set distributed randomly;
Alter table abc set with (reorganize=false) distributed randomly;
WARNING:  distribution policy of relation "abc" already set to DISTRIBUTED RANDOMLY
HINT:  Use ALTER TABLE "abc" SET WITH (REORGANIZE=TRUE) DISTRIBUTED RANDOMLY to force a random redistribution
drop table abc;
-- MPP-7770: disable changing storage options (default, for now)
set gp_setwith_alter_storage = false;
-- disallow, so fails
create table atsdb (i int, j text) distributed by (j);
alter table atsdb set with(appendonly = true);
ERROR:  option "appendonly" not supported
drop table atsdb;
-- MPP-8474: Index relfilenode mismatch: entry db to segment db.
--
-- XXX This really belongs in alter_table.sql but this is not 
--     in use in current_good_schedule.
drop table if exists mpp8474 cascade; --ignore
NOTICE:  table "mpp8474" does not exist, skipping
create table mpp8474(a int, b int, c text) 
    with (appendonly=true) 
    distributed by (b);
create index mpp8474_a 
    on mpp8474(a);
alter table mpp8474 
    add column d int default 10;
select 
    'Mismatched relfilenodes:' as oops,
    e.oid::regclass as entry_oid,
    e.relkind,
    e.relfilenode as entry_relfilenode,
    s.segid,
    s.segfilenode as segment_relfilenode
from 
    pg_class e,
    (   select gp_execution_segment(), oid, relfilenode
        from gp_dist_random('pg_class')
    ) s (segid, segoid, segfilenode)
where 
    e.oid = s.segoid 
    and e.relfilenode != s.segfilenode
    and e.relname ~ '^mpp8474.*';
 oops | entry_oid | relkind | entry_relfilenode | segid | segment_relfilenode 
------+-----------+---------+-------------------+-------+---------------------
(0 rows)

drop table mpp8474;
-- MPP-18660: duplicate entry in gp_distribution_policy
set enable_indexscan=on;
set enable_seqscan=off;
drop table if exists distrib_index_test;
NOTICE:  table "distrib_index_test" does not exist, skipping
create table distrib_index_test (a int, b text) distributed by (a);
select count(*) from gp_distribution_policy 
	where localoid in (select oid from pg_class where relname='distrib_index_test');
 count 
-------
     1
(1 row)

begin;
drop table distrib_index_test;
rollback;
select count(*) from gp_distribution_policy 
	where localoid in (select oid from pg_class where relname='distrib_index_test');
 count 
-------
     1
(1 row)

reset enable_indexscan;
reset enable_seqscan;
drop table distrib_index_test;
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
-- alter partitioned table crash
-- Alter partitioned table set distributed by will crash when:
--     1. reorganize = false.
--     2. table have index.
--     3. partition table have "with" option.
drop index if exists distrib_part_test_idx;
NOTICE:  index "distrib_part_test_idx" does not exist, skipping
drop table if exists distrib_part_test;
NOTICE:  table "distrib_part_test" does not exist, skipping
CREATE TABLE distrib_part_test
(
  col1 int,
  col2 decimal,
  col3 text,
  col4 bool
)
distributed by (col1)
partition by list(col2)
(
    partition part1 values(1,2,3,4,5,6,7,8,9,10) WITH (appendonly=false )
);
NOTICE:  CREATE TABLE will create partition "distrib_part_test_1_prt_part1" for table "distrib_part_test"
create index distrib_part_test_idx on distrib_part_test(col1);
NOTICE:  building index for child partition "distrib_part_test_1_prt_part1"
ALTER TABLE public.distrib_part_test SET with (reorganize=false) DISTRIBUTED RANDOMLY;