Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-06-19 0cfc87bd32822e5ba22d8c2b1a26fa60f63ad7fa
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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
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
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
create table tab0(c0 integer);
create table tab1(c1 integer);
create table tab2(c2 integer);
create table tab3(c3 integer);
create table tab4(c4 integer);
create table tab5(c5 integer);
create table tab6(c6 integer);
create table tab7(c7 integer);
create table tab8(c8 integer);
create table tab9(c9 integer);
 
create table tab10(c10 integer);
create table tab11(c11 integer);
create table tab12(c12 integer);
create table tab13(c13 integer);
create table tab14(c14 integer);
create table tab15(c15 integer);
create table tab16(c16 integer);
create table tab17(c17 integer);
create table tab18(c18 integer);
create table tab19(c19 integer);
 
create index idx0 on tab0 (c0);
create index idx1 on tab1 (c1);
create index idx2 on tab2 (c2);
create index idx3 on tab3 (c3);
create index idx4 on tab4 (c4);
create index idx5 on tab5 (c5);
create index idx6 on tab6 (c6);
create index idx7 on tab7 (c7);
create index idx8 on tab8 (c8);
create index idx9 on tab9 (c9);
create index idx10 on tab10 (c10);
create index idx11 on tab11 (c11);
create index idx12 on tab12 (c12);
create index idx13 on tab13 (c13);
create index idx14 on tab14 (c14);
create index idx15 on tab15 (c15);
create index idx16 on tab16 (c16);
create index idx17 on tab17 (c17);
create index idx18 on tab18 (c18);
create index idx19 on tab19 (c19);
 
insert into tab0 select id from generate_series(1,10) as g(id);
insert into tab1 select id from generate_series(1,10) as g(id);
insert into tab2 select id from generate_series(1,10) as g(id);
insert into tab3 select id from generate_series(1,10) as g(id);
insert into tab4 select id from generate_series(1,10) as g(id);
insert into tab5 select id from generate_series(1,10) as g(id);
insert into tab6 select id from generate_series(1,10) as g(id);
insert into tab7 select id from generate_series(1,10) as g(id);
insert into tab8 select id from generate_series(1,10) as g(id);
insert into tab9 select id from generate_series(1,10) as g(id);
 
insert into tab10 select id from generate_series(1,10) as g(id);
insert into tab11 select id from generate_series(1,10) as g(id);
insert into tab12 select id from generate_series(1,10) as g(id);
insert into tab13 select id from generate_series(1,10) as g(id);
insert into tab14 select id from generate_series(1,10) as g(id);
insert into tab15 select id from generate_series(1,10) as g(id);
insert into tab16 select id from generate_series(1,10) as g(id);
insert into tab17 select id from generate_series(1,10) as g(id);
insert into tab18 select id from generate_series(1,10) as g(id);
insert into tab19 select id from generate_series(1,10) as g(id);
 
-------------------------------------------------------stand
 
CREATE DOMAIN dsspid AS numeric(15,0) DEFAULT 0;
CREATE DOMAIN dsidentifier AS numeric(15,0) DEFAULT 0;
CREATE DOMAIN dsoperday AS timestamp(0) without time zone DEFAULT '1900-01-01 00:00:00'::timestamp without time zone;
CREATE DOMAIN dsfullname AS character(60) DEFAULT ''::bpchar;
CREATE DOMAIN dsbriefname AS character(10) DEFAULT ''::bpchar;
CREATE DOMAIN dsfieldnamevar AS character varying(30) DEFAULT ''::character varying;
CREATE DOMAIN dstinyint AS smallint DEFAULT 0;
CREATE DOMAIN dscomment AS character varying(255) DEFAULT ''::character varying;
CREATE DOMAIN dsacc_swift AS character(35) DEFAULT ''::bpchar;
CREATE DOMAIN dsbigmoney AS numeric(28,10) DEFAULT 0;
CREATE DOMAIN dsfloat AS double precision DEFAULT 0;
CREATE DOMAIN dsmoney AS numeric(19,4) DEFAULT 0;
CREATE DOMAIN dsaccnumvar AS character varying(25) DEFAULT ''::character varying;
CREATE DOMAIN dsaccnumber AS character(25) DEFAULT ''::bpchar;
CREATE DOMAIN dsint_key AS integer DEFAULT 0;
CREATE DOMAIN dsdatetime AS timestamp(3) without time zone DEFAULT '1900-01-01 00:00:00'::timestamp without time zone;
CREATE DOMAIN dsvarfullname AS character varying(60) DEFAULT ''::character varying;
CREATE DOMAIN dssmallint AS smallint DEFAULT 0;
CREATE DOMAIN dsfieldname AS character(30) DEFAULT ''::bpchar;
CREATE DOMAIN day AS timestamp(0) without time zone DEFAULT (((to_char(CURRENT_TIMESTAMP, 'YEAR'::text) || to_char(CURRENT_TIMESTAMP, 'MONTH'::text)) || to_char(CURRENT_TIMESTAMP, 'DAY'::text)))::timestamp(0) without time zone;
CREATE DOMAIN dsvarfullname40 AS character varying(40) DEFAULT ''::character varying;
CREATE DOMAIN dsbic AS character varying(15) DEFAULT ''::character varying;
CREATE DOMAIN dsusername AS character(30) DEFAULT ''::bpchar;
CREATE DOMAIN dsvarfullname160 AS character varying(160) DEFAULT ''::character varying;
CREATE DOMAIN dsnumber20 AS character(20) DEFAULT '         0'::bpchar;
CREATE DOMAIN dsbriefvar AS character varying(10) DEFAULT ''::character varying;
CREATE DOMAIN dshash AS character varying(120) DEFAULT '%'::character varying;
CREATE DOMAIN dslabel AS character varying(80) DEFAULT ''::character varying;
CREATE DOMAIN dsnumber AS character(10) DEFAULT '         0'::bpchar;
CREATE DOMAIN dsbit0 AS smallint DEFAULT 0;
 
 
CREATE UNLOGGED SEQUENCE prest2_numid_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
    CYCLE;
 
---plastdate2
CREATE UNLOGGED TABLE plastdate2 (
    spid dsspid,
    resourceid dsidentifier,
    lastdate dsoperday,
    fundid dsidentifier
);
 
ALTER TABLE ONLY plastdate2
    ADD CONSTRAINT plastdate2_xpkplastdate2 UNIQUE (spid, resourceid, fundid, lastdate) DEFERRABLE;
 
---prest2
CREATE UNLOGGED TABLE prest2 (
    spid dsspid,
    resourceid dsidentifier,
    rest dsbigmoney,
    restbs dsbigmoney,
    turndeb dsbigmoney,
    turncre dsbigmoney,
    turndebbs dsbigmoney,
    turncrebs dsbigmoney,
    lastdate dsoperday,
    fundid dsidentifier,
    securityid dsidentifier,
    resourcetype dstinyint,
    numdoc dsint_key,
    parentid dsidentifier,
    numid dsidentifier DEFAULT nextval('prest2_numid_seq'::regclass),
    flagparent dstinyint
);
 
ALTER TABLE ONLY prest2
    ADD CONSTRAINT prest2_xpktrest UNIQUE (spid, resourceid, fundid) DEFERRABLE;
CREATE INDEX prest2_xie8trest ON prest2 USING btree (spid, numid);
 
---trest
CREATE TABLE trest (
    date dsoperday NOT NULL,
    resourceid dsidentifier NOT NULL,
    confirmed dstinyint NOT NULL,
    institutionid dsidentifier NOT NULL,
    rest dsbigmoney NOT NULL,
    restbs dsbigmoney NOT NULL,
    turndeb dsbigmoney NOT NULL,
    turncre dsbigmoney NOT NULL,
    turndebbs dsbigmoney NOT NULL,
    turncrebs dsbigmoney NOT NULL,
    lastdate dsoperday NOT NULL,
    fundid dsidentifier NOT NULL,
    securityid dsidentifier NOT NULL,
    resourcetype dstinyint NOT NULL,
    balanceid dsidentifier NOT NULL,
    numdoc dsint_key NOT NULL,
    accountingtype dsint_key NOT NULL
);
 
ALTER TABLE ONLY trest
    ADD CONSTRAINT trest_xpktrest UNIQUE (accountingtype, date, resourceid, fundid, institutionid) DEFERRABLE;
CREATE INDEX trest_xie2trest ON trest USING btree (resourceid, accountingtype, date, lastdate);
CREATE INDEX trest_xie3trest ON trest USING btree (accountingtype, institutionid, date);
CREATE INDEX trest_xie4trest ON trest USING btree (accountingtype, fundid, securityid);
CREATE INDEX trest_xie5trest ON trest USING btree (accountingtype, institutionid, resourceid, date);
CREATE INDEX trest_xie6trest ON trest USING btree (accountingtype, balanceid, institutionid, date);
 
---tMMRegAnalytics
CREATE TABLE tmmreganalytics (
    mmregid dsidentifier NOT NULL,
    mmanalyticsid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tmmreganalytics
    ADD CONSTRAINT tmmreganalytics_xak1tmmreganalytics UNIQUE (mmanalyticsid, mmregid) DEFERRABLE;
ALTER TABLE ONLY tmmreganalytics
    ADD CONSTRAINT tmmreganalytics_xpktmmreganalytics UNIQUE (mmregid, mmanalyticsid) DEFERRABLE;
 
---pMMRegisterID
CREATE UNLOGGED TABLE pmmregisterid (
    spid dsspid,
    linkid dsidentifier,
    mmregid dsidentifier,
    id bigint NOT NULL
);
ALTER TABLE ONLY pmmregisterid ALTER COLUMN spid SET STATISTICS 0;
 
ALTER TABLE pmmregisterid ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME pmmregisterid_id_seq1
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);
ALTER SEQUENCE pmmregisterid_id_seq1 SET LOGGED;
CREATE UNIQUE INDEX pmmregisterid_xakpmmregisterid ON pmmregisterid USING btree (spid, id);
CREATE UNIQUE INDEX pmmregisterid_xpkpmmregisterid ON pmmregisterid USING btree (spid, linkid);
 
---pMMAnalyticMassInsert
CREATE UNLOGGED TABLE pmmanalyticmassinsert (
    spid dsspid,
    linkid dsidentifier,
    mmanalyticstypeid dsidentifier,
    analyticsobjectid dsidentifier
);
ALTER TABLE ONLY pmmanalyticmassinsert ALTER COLUMN spid SET STATISTICS 0;
CREATE UNIQUE INDEX pmmanalyticmassinsert_xpkpmmanalyticmassinsert ON pmmanalyticmassinsert USING btree (spid, linkid, mmanalyticstypeid);
 
---pMMAnalyticDeal2
CREATE UNLOGGED TABLE pmmanalyticdeal2 (
    spid dsspid,
    mmanalyticstypeid dsidentifier,
    analyticsobjectid dsidentifier,
    mmanalyticsid dsidentifier,
    id bigint NOT NULL
);
ALTER TABLE ONLY pmmanalyticdeal2 ALTER COLUMN spid SET STATISTICS 0;
ALTER TABLE pmmanalyticdeal2 ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME pmmanalyticdeal2_id_seq1
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);
ALTER SEQUENCE pmmanalyticdeal2_id_seq1 SET LOGGED;
CREATE UNIQUE INDEX pmmanalyticdeal2_xpkpmmanalyticdeal2 ON pmmanalyticdeal2 USING btree (spid, mmanalyticstypeid, analyticsobjectid);
 
---pdpt_accrual_advlucre
CREATE UNLOGGED TABLE pdpt_accrual_advlucre (
    spid dsspid,
    objectid dsidentifier,
    fundid dsidentifier,
    advtax dsmoney,
    templatenumber dsidentifier,
    begindate dsoperday,
    prcdate dsoperday,
    enddate dsoperday,
    value dsmoney,
    prcnt dsfloat,
    preparedqty dsmoney,
    templatenumberprc dsint_key,
    protocolid dsidentifier
);
 
CREATE INDEX pdpt_accrual_advlucre_xpkpdpt_accrual_advlucre ON pdpt_accrual_advlucre USING btree (spid, objectid, templatenumber);
 
---pdealid_mark
CREATE UNLOGGED TABLE pdealid_mark (
    spid dsspid,
    dealid dsidentifier,
    datebegin dsoperday,
    dateend dsoperday,
    instrumentid dsidentifier,
    flag dstinyint
);
 
 
CREATE INDEX pdealid_mark_xie0pdealid_mark ON pdealid_mark USING btree (spid, dealid);
CREATE INDEX pdealid_mark_xie1pdealid_mark ON pdealid_mark USING btree (spid, instrumentid, datebegin, dateend);
 
---pdpt_accrual_advac
CREATE UNLOGGED TABLE pdpt_accrual_advac (
    spid dsspid,
    objectid dsidentifier,
    templatenumber dsidentifier,
    fundid dsidentifier,
    advondate dsoperday,
    advtaxrub dsmoney,
    corrdate dsoperday,
    prcnt dsfloat
);
 
ALTER TABLE ONLY pdpt_accrual_advac
    ADD CONSTRAINT pdpt_accrual_advac_xpkpdpt_accrual_advac UNIQUE (spid, objectid, templatenumber, advondate) DEFERRABLE;
 
CREATE INDEX pdpt_accrual_advac_xak1pdpt_accrual_advac ON pdpt_accrual_advac USING btree (spid, templatenumber, objectid);
 
---pTmp_DocumentBuffer
CREATE TABLE pTmp_DocumentBuffer (
id bigint GENERATED ALWAYS AS IDENTITY,
opcode DSTINYINT,
batchid DSIDENTIFIER,
confirmed DSTINYINT,
qtydeb DSBIGMONEY,
funddebid DSIDENTIFIER,
qtycre DSBIGMONEY,
fundcreid DSIDENTIFIER,
comment DSCOMMENT,
branchid DSIDENTIFIER,
balanceid DSIDENTIFIER,
accanlid DSIDENTIFIER,
accanlsecid DSIDENTIFIER,
priority DSFLOAT,
paymenttype DSIDENTIFIER,
templatetype DSIDENTIFIER,
docinstrumentid DSIDENTIFIER,
resdebid DSIDENTIFIER,
rescreid DSIDENTIFIER,
date DSOPERDAY,
debsubcontosetid DSIDENTIFIER,
cresubcontosetid DSIDENTIFIER,
dealprotocolid DSIDENTIFIER,
qtybs DSBIGMONEY,
course DSFLOAT,
objectid DSIDENTIFIER,
opertemplateid DSIDENTIFIER,
instrumentid DSIDENTIFIER,
dealid DSIDENTIFIER,
mainobjectid DSIDENTIFIER,
groupid DSIDENTIFIER,
flags DSINT_KEY,
accountingtype DSINT_KEY,
retcode DSIDENTIFIER,
fundid DSIDENTIFIER,
qtypsv DSBIGMONEY,
fundpsvid DSIDENTIFIER,
qtycrebs DSBIGMONEY,
tradingsysid DSIDENTIFIER,
resourcepid DSIDENTIFIER,
resourcemid DSIDENTIFIER,
centcopeck DSSMALLINT,
docnumber DSACCNUMBER null
);
CREATE INDEX pTmp_DocumentBuffer_XIE0DocumentBuffer ON pTmp_DocumentBuffer(RetCode);
CREATE INDEX pTmp_DocumentBuffer_XIE1DocumentBuffer ON pTmp_DocumentBuffer(OperTemplateID,ObjectID);
CREATE INDEX pTmp_DocumentBuffer_XIE2DocumentBuffer ON pTmp_DocumentBuffer(GroupID);
CREATE UNIQUE INDEX pTmp_DocumentBuffer_XIE3DocumentBuffer ON pTmp_DocumentBuffer(ID); 
;
INSERT INTO pTmp_DocumentBuffer(objectid)
SELECT 10042002030 + i FROM generate_series(1, 30000) s(i)
;
 
---pFX_TermRegister
CREATE UNLOGGED TABLE pfx_termregister (
    spid dsspid,
    objectid dsidentifier,
    mmregid dsidentifier,
    value dsbigmoney,
    liabtype dsidentifier,
    currencyid dsidentifier,
    termrule dsidentifier,
    termtype dsidentifier,
    termoperation dsidentifier,
    maturity dsidentifier
);
ALTER TABLE ONLY pfx_termregister ALTER COLUMN spid SET STATISTICS 0;
CREATE INDEX pfx_termregister_xie1pfx_termregister ON pfx_termregister USING btree (spid, liabtype, objectid);
CREATE INDEX pfx_termregister_xpkpfx_termregister ON pfx_termregister USING btree (spid, objectid);
 
---tMMReg
CREATE TABLE tmmreg (
    mmregid dsidentifier NOT NULL,
    date dsoperday NOT NULL,
    value dsbigmoney NOT NULL,
    mmregtypeid dsidentifier NOT NULL,
    objecttypeid dsint_key NOT NULL,
    objectid dsidentifier NOT NULL,
    parentid dsidentifier NOT NULL,
    userid dsidentifier NOT NULL,
    indatetime dsdatetime NOT NULL,
    comment dscomment NOT NULL,
    protocolid dsidentifier,
    dsmoduleid dsidentifier,
    currencyid dsidentifier,
    processingstatus dstinyint
);
 
ALTER TABLE ONLY tmmreg
    ADD CONSTRAINT tmmreg_xak1tmmreg UNIQUE (protocolid, mmregid) DEFERRABLE;
ALTER TABLE ONLY tmmreg
    ADD CONSTRAINT tmmreg_xpktmmreg UNIQUE (mmregid) DEFERRABLE;
CREATE INDEX tmmreg_xie1tmmreg ON tmmreg USING btree (date, mmregtypeid, objecttypeid, dsmoduleid);
CREATE INDEX tmmreg_xie2tmmreg ON tmmreg USING btree (objectid, objecttypeid, date);
CREATE INDEX tmmreg_xie3tmmreg ON tmmreg USING btree (parentid);
 
---tMMAnalytics
CREATE TABLE tmmanalytics (
    mmanalyticsid dsidentifier NOT NULL,
    mmanalyticstypeid dsidentifier NOT NULL,
    analyticsobjectid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tmmanalytics
    ADD CONSTRAINT tmmanalytics_xak1tmmanalytics UNIQUE (mmanalyticstypeid, analyticsobjectid) DEFERRABLE;
ALTER TABLE ONLY tmmanalytics
    ADD CONSTRAINT tmmanalytics_xpktmmanalytics UNIQUE (mmanalyticsid) DEFERRABLE;
 
---pobject2_numid_seq
CREATE UNLOGGED SEQUENCE pobject2_numid_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
    CYCLE;
 
---pObject2
CREATE UNLOGGED TABLE pobject2 (
    spid dsidentifier,
    objectid dsidentifier,
    instrumentid dsidentifier,
    actionid dsidentifier,
    date dsoperday,
    operdate dsoperday,
    plandate dsoperday,
    errorcode dsint_key,
    legalbaseid dsidentifier,
    numid dsidentifier DEFAULT nextval('pobject2_numid_seq'::regclass),
    unneedrlbckprot dstinyint,
    errormessage dscomment
);
 
ALTER TABLE ONLY pobject2
    ADD CONSTRAINT pobject2_xpkpobject2 UNIQUE (spid, objectid) DEFERRABLE;
CREATE INDEX pobject2_xak1pobject2 ON pobject2 USING btree (spid, numid);
CREATE INDEX pobject2_xie1pobject2 ON pobject2 USING btree (spid, errorcode, objectid);
 
---pfx_termdealparam
CREATE UNLOGGED TABLE pfx_termdealparam (
    spid dsspid,
    objectid dsidentifier,
    instrumentid dsidentifier,
    branchid dsidentifier,
    institutionid dsidentifier,
    keeperid dsidentifier,
    dealnumber dsaccnumvar,
    securityid dsidentifier,
    fundid dsidentifier,
    instpercent dsfloat,
    dealtype dstinyint,
    dealdate dsoperday,
    registdate dsoperday,
    contrdate dsoperday,
    qty dsbigmoney,
    registpaytype dsidentifier,
    trmregdemvalue dsbigmoney,
    trmregdemcurrencyid dsidentifier,
    trmregdemmaturity dsidentifier,
    trmregliabvalue dsbigmoney,
    trmregliabcurrencyid dsidentifier,
    trmregliabmaturity dsidentifier,
    rdcregdemvalue dsbigmoney,
    rdcregdemcurrencyid dsidentifier,
    rdcregliabvalue dsbigmoney,
    rdcregliabcurrencyid dsidentifier
);
ALTER TABLE ONLY pfx_termdealparam ALTER COLUMN spid SET STATISTICS 0;
CREATE UNIQUE INDEX pfx_termdealparam_xpkpfx_termdealparam ON pfx_termdealparam USING btree (spid, objectid);
 
---pobject_numid_seq
CREATE UNLOGGED SEQUENCE pobject_numid_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
    CYCLE;
 
---pobject
CREATE UNLOGGED TABLE pobject (
    spid dsidentifier,
    objectid dsidentifier,
    instrumentid dsidentifier,
    actionid dsidentifier,
    date dsoperday,
    operdate dsoperday,
    plandate dsoperday,
    errorcode dsint_key,
    legalbaseid dsidentifier,
    numid dsidentifier DEFAULT nextval('pobject_numid_seq'::regclass),
    unneedrlbckprot dstinyint
);
 
ALTER TABLE ONLY pobject
    ADD CONSTRAINT pobject_xpkpobject UNIQUE (spid, objectid) DEFERRABLE;
CREATE INDEX pobject_xak1pobject ON pobject USING btree (spid, numid);
CREATE INDEX pobject_xie1pobject ON pobject USING btree (spid, errorcode);
 
---tactionperiod
CREATE TABLE tactionperiod (
    actionperiodid dsidentifier NOT NULL,
    nodeid dsidentifier NOT NULL,
    schemeperiodid dsidentifier NOT NULL,
    priority dsint_key NOT NULL,
    objectid dsidentifier NOT NULL
);
CREATE INDEX tactionperiod_xie1tactionperiod ON tactionperiod USING btree (nodeid, objectid, schemeperiodid);
CREATE INDEX tactionperiod_xie2tactionperiod ON tactionperiod USING btree (schemeperiodid);
CREATE UNIQUE INDEX tactionperiod_xpktactionperiod ON tactionperiod USING btree (actionperiodid);
 
---tDocMark
CREATE TABLE tdocmark (
    spid dsspid,
    type dsint_key,
    id dsidentifier
);
 
ALTER TABLE ONLY tdocmark
    ADD CONSTRAINT tdocmark_xpktdocmark UNIQUE (spid, type, id) DEFERRABLE;
 
---tActionPlan
CREATE TABLE tactionplan (
    actionplanid dsidentifier NOT NULL,
    objectid dsidentifier NOT NULL,
    actionperiodid dsidentifier NOT NULL,
    plandate dsoperday NOT NULL,
    factdate dsoperday NOT NULL,
    operdate dsoperday NOT NULL,
    branchid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tactionplan
    ADD CONSTRAINT tactionplan_xak1tactionplan UNIQUE (objectid, actionperiodid) DEFERRABLE;
ALTER TABLE ONLY tactionplan
    ADD CONSTRAINT tactionplan_xpktactionplan UNIQUE (actionplanid) DEFERRABLE;
CREATE INDEX tactionplan_xie1tactionplan ON tactionplan USING btree (actionperiodid, branchid, operdate);
 
---pTblCursor5
CREATE UNLOGGED TABLE ptblcursor5 (
    spid dsspid,
    type dstinyint,
    id dsidentifier
);
 
ALTER TABLE ONLY ptblcursor5
    ADD CONSTRAINT ptblcursor5_xpkptblcursor5 UNIQUE (spid, type, id) DEFERRABLE;
 
---tObject
CREATE TABLE tobject (
    objectid dsidentifier NOT NULL,
    objecttypeid dsint_key NOT NULL,
    id dsidentifier NOT NULL,
    instrumentid dsidentifier NOT NULL,
    currprotocolid dsidentifier NOT NULL,
    branchid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tobject
    ADD CONSTRAINT tobject_xak2tobject UNIQUE (instrumentid, id) DEFERRABLE;
ALTER TABLE ONLY tobject
    ADD CONSTRAINT tobject_xpktobject UNIQUE (objectid) DEFERRABLE;
CREATE INDEX tobject_xak1tobject ON tobject USING btree (id, objecttypeid);
CREATE INDEX tobject_xie2tobject ON tobject USING btree (currprotocolid);
 
---tProtocol
CREATE TABLE tprotocol (
    protocolid dsidentifier NOT NULL,
    objectid dsidentifier NOT NULL,
    date dsoperday NOT NULL,
    transitionid dsidentifier NOT NULL,
    stateorder dsint_key NOT NULL,
    auditid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tprotocol
    ADD CONSTRAINT tprotocol_xpktprotocol UNIQUE (protocolid) DEFERRABLE;
CREATE INDEX tprotocol_xak1tprotocol ON tprotocol USING btree (objectid, stateorder);
CREATE INDEX tprotocol_xie1tprotocol ON tprotocol USING btree (transitionid);
 
---tTransition
CREATE TABLE ttransition (
    transitionid dsidentifier NOT NULL,
    instrumentid dsidentifier NOT NULL,
    sourcestateid dsidentifier NOT NULL,
    actionid dsidentifier NOT NULL,
    targetstateid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY ttransition
    ADD CONSTRAINT ttransition_xak1ttransition UNIQUE (instrumentid, sourcestateid, targetstateid, actionid) DEFERRABLE;
ALTER TABLE ONLY ttransition
    ADD CONSTRAINT ttransition_xpkttransition UNIQUE (transitionid) DEFERRABLE;
CREATE INDEX ttransition_xie1ttransition ON ttransition USING btree (sourcestateid);
 
---tOperSet
CREATE TABLE toperset (
    opersetid dsidentifier NOT NULL,
    instrumentid dsidentifier NOT NULL,
    name dsfullname NOT NULL,
    brief dsfieldname NOT NULL,
    dealtype dstinyint NOT NULL,
    number dstinyint NOT NULL,
    actiontype dstinyint NOT NULL,
    oninput dstinyint NOT NULL,
    onconfirm dstinyint NOT NULL,
    parentid dsidentifier NOT NULL,
    childid dsidentifier NOT NULL,
    objectid dsidentifier NOT NULL,
    configstyleid dsidentifier NOT NULL,
    date dsoperday NOT NULL
);
 
ALTER TABLE ONLY toperset
    ADD CONSTRAINT toperset_xak0toperset UNIQUE (parentid, childid, configstyleid, date, number) DEFERRABLE;
ALTER TABLE ONLY toperset
    ADD CONSTRAINT toperset_xak1toperset UNIQUE (parentid, childid, number) DEFERRABLE;
ALTER TABLE ONLY toperset
    ADD CONSTRAINT toperset_xpktoperset UNIQUE (opersetid) DEFERRABLE;
CREATE INDEX toperset_xie0toperset ON toperset USING btree (actiontype, configstyleid);
CREATE INDEX toperset_xie1toperset ON toperset USING btree (childid);
 
---tPeriod
CREATE TABLE tperiod (
    periodid dsidentifier NOT NULL,
    schemeperiodid dsidentifier NOT NULL,
    name dsfullname NOT NULL,
    type dsint_key NOT NULL,
    algorithm dsidentifier NOT NULL,
    starttype dsidentifier NOT NULL,
    startdate dsoperday NOT NULL,
    startalgorithm dsidentifier NOT NULL,
    period dsint_key NOT NULL,
    periodtype dsint_key NOT NULL,
    periodalgorithm dsidentifier NOT NULL,
    periodvalue dsint_key NOT NULL,
    adddays dsint_key NOT NULL,
    payperiod dsint_key NOT NULL,
    payday dsint_key NOT NULL,
    paymonth dsint_key NOT NULL,
    factalgorithm dsidentifier NOT NULL,
    operalgorithm dsidentifier NOT NULL,
    specalgorithm dsidentifier NOT NULL,
    endtype dsint_key NOT NULL,
    paydirection dsint_key NOT NULL,
    calendarid dsidentifier NOT NULL,
    correcttypestart dsint_key NOT NULL,
    correctvaluestart dsint_key NOT NULL,
    correcttypeperiod dsint_key NOT NULL,
    correctend dsint_key NOT NULL,
    periodpriority dsint_key NOT NULL,
    calendarfactid dsidentifier NOT NULL,
    calendarspecid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tperiod
    ADD CONSTRAINT tperiod_xpktperiod UNIQUE (periodid) DEFERRABLE;
CREATE INDEX tperiod_xie1tperiod ON tperiod USING btree (schemeperiodid);
 
---pErrorObject
CREATE UNLOGGED TABLE perrorobject (
    spid dsspid,
    objectid dsidentifier,
    instrumentid dsidentifier,
    nodeid dsidentifier,
    errorcode dsint_key
);
 
ALTER TABLE ONLY perrorobject
    ADD CONSTRAINT perrorobject_xpkperrorobject UNIQUE (spid, objectid, instrumentid, nodeid) DEFERRABLE;
CREATE INDEX perrorobject_xie1perrorobject ON perrorobject USING btree (spid, nodeid);
 
---papi_prmd_idlist
 
CREATE UNLOGGED TABLE papi_prmd_idlist (
    accountid dsidentifier,
    accountnumber dsacc_swift,
    linkid dsidentifier,
    objectid dsidentifier,
    objecttype dstinyint,
    prmdid dsidentifier,
    spid dsspid,
    prmdtype dstinyint
);
 
CREATE INDEX papi_prmd_idlist_xie1papi_prmd_idlist ON papi_prmd_idlist USING btree (spid, linkid);
CREATE INDEX papi_prmd_idlist_xpkpapi_prmd_idlist ON papi_prmd_idlist USING btree (spid, prmdid);
 
---prko_prmd_accidlist
 
CREATE UNLOGGED TABLE prko_prmd_accidlist (
    spid dsspid,
    accountid dsidentifier,
    accountnumber dsacc_swift,
    foundedaccid dsidentifier
);
 
CREATE INDEX prko_prmd_accidlist_xpkprko_prmd_accidlist ON prko_prmd_accidlist USING btree (spid, foundedaccid);
 
---tdealtransact
 
CREATE TABLE tdealtransact (
    dealtransactid dsidentifier NOT NULL,
    dealid dsidentifier NOT NULL,
    instrumentid dsidentifier NOT NULL,
    transacttype dstinyint NOT NULL,
    resourceid dsidentifier NOT NULL,
    ressecondid dsidentifier NOT NULL,
    fundid dsidentifier NOT NULL,
    date dsoperday NOT NULL,
    qty dsbigmoney NOT NULL,
    fixqty dsbigmoney NOT NULL,
    fixcourse dsfloat NOT NULL,
    fixdate dsoperday NOT NULL,
    realcourse dsfloat NOT NULL,
    realqty dsbigmoney NOT NULL,
    confirmed dstinyint NOT NULL,
    direction dstinyint NOT NULL,
    type dstinyint NOT NULL,
    parentid dsidentifier NOT NULL,
    nettqty dsmoney NOT NULL,
    securityid dsidentifier NOT NULL,
    institutionid dsidentifier NOT NULL,
    userid dsidentifier NOT NULL,
    instsecondid dsidentifier NOT NULL,
    indatetime day NOT NULL,
    pass dstinyint NOT NULL,
    expenseprc dsfloat NOT NULL,
    expenseqty dsmoney NOT NULL,
    expensefundid dsidentifier NOT NULL,
    expensecourse dsfloat NOT NULL,
    balancecourse dsfloat NOT NULL,
    balanceqty dsbigmoney NOT NULL,
    docdate dsoperday NOT NULL,
    docnumber dsaccnumvar NOT NULL,
    courierid dsidentifier NOT NULL,
    comment dscomment NOT NULL,
    secissueid dsidentifier NOT NULL,
    resourcepsvid dsidentifier NOT NULL,
    ressecondpsvid dsidentifier NOT NULL,
    dealprotocolid dsidentifier NOT NULL,
    certificateid dsidentifier NOT NULL,
    series dsaccnumvar NOT NULL,
    numberext dsaccnumber NOT NULL,
    numberlow dsint_key NOT NULL,
    numberhigh dsint_key NOT NULL,
    nominal dsmoney NOT NULL,
    couponid dsidentifier NOT NULL,
    batchid dsidentifier NOT NULL,
    opcode dsidentifier NOT NULL,
    proctype dsidentifier NOT NULL,
    priority dsidentifier NOT NULL,
    termdate dsdatetime NOT NULL,
    prognumber dsidentifier NOT NULL,
    valuedate dsdatetime NOT NULL,
    docname dsvarfullname NOT NULL,
    balanceid dsidentifier NOT NULL,
    fundpsvid dsidentifier NOT NULL,
    activeflag dstinyint NOT NULL,
    nettresultid dsidentifier NOT NULL,
    nettobjectid dsidentifier NOT NULL,
    objectstate dsidentifier NOT NULL,
    paymenttype dsidentifier NOT NULL,
    accanlid dsidentifier NOT NULL,
    accanlsecid dsidentifier NOT NULL,
    initiatorid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tdealtransact
    ADD CONSTRAINT tdealtransact_xpktdealtransact UNIQUE (dealtransactid) DEFERRABLE;
CREATE INDEX tdealtransact_xie10tdealtransact ON tdealtransact USING btree (initiatorid);
CREATE INDEX tdealtransact_xie11tdealtransact ON tdealtransact USING btree (fundid, expensefundid, securityid, secissueid);
CREATE INDEX tdealtransact_xie12tdealtransact ON tdealtransact USING btree (fixdate, transacttype, securityid);
CREATE INDEX tdealtransact_xie13tdealtransact ON tdealtransact USING btree (transacttype, docdate, accanlid, instrumentid);
CREATE INDEX tdealtransact_xie14tdealtransact ON tdealtransact USING btree (resourcepsvid, date);
CREATE INDEX tdealtransact_xie1tdealtransact ON tdealtransact USING btree (dealid, transacttype, dealprotocolid);
CREATE INDEX tdealtransact_xie2tdealtransact ON tdealtransact USING btree (parentid, transacttype, type);
CREATE INDEX tdealtransact_xie3tdealtransact ON tdealtransact USING btree (transacttype, date, instrumentid, resourcepsvid, prognumber);
CREATE INDEX tdealtransact_xie4tdealtransact ON tdealtransact USING btree (transacttype, activeflag, balanceid, couponid);
CREATE INDEX tdealtransact_xie6tdealtransact ON tdealtransact USING btree (dealprotocolid);
CREATE INDEX tdealtransact_xie8tdealtransact ON tdealtransact USING btree (transacttype, date, qty);
CREATE INDEX tdealtransact_xie9tdealtransact ON tdealtransact USING btree (resourceid, date);
 
---papi_sm_linkedprotocol
 
CREATE UNLOGGED TABLE papi_sm_linkedprotocol (
    spid dsspid,
    finoperid dsidentifier,
    objectid dsidentifier,
    objecttypeid dsidentifier,
    protocolid dsidentifier,
    relationtype dsint_key
);
 
CREATE INDEX papi_sm_linkedprotocol_xpkpapi_sm_linkedprotocol ON papi_sm_linkedprotocol USING btree (spid, relationtype, protocolid);
 
---tprotocolrelation
 
CREATE TABLE tprotocolrelation (
    parentid dsidentifier NOT NULL,
    childid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tprotocolrelation
    ADD CONSTRAINT tprotocolrelation_xpktprotocolrelation UNIQUE (parentid, childid) DEFERRABLE;
 
CREATE INDEX tprotocolrelation_xie1tprotocolrelation ON tprotocolrelation USING btree (childid);
 
---pdpt_accrual_advbase
 
CREATE UNLOGGED TABLE pdpt_accrual_advbase (
    spid dsspid,
    objectid dsidentifier,
    basevalue dsmoney,
    tax dsfloat,
    advtax dsfloat,
    qty dsfloat,
    refqty dsfloat,
    templatenumber dsidentifier,
    begindate dsoperday,
    enddate dsoperday,
    protocolid dsidentifier
);
 
CREATE INDEX pdpt_accrual_advbase_xak1pdpt_accrual_advbase ON pdpt_accrual_advbase USING btree (spid, templatenumber, objectid);
CREATE INDEX pdpt_accrual_advbase_xpkpdpt_accrual_advbase ON pdpt_accrual_advbase USING btree (spid, objectid, templatenumber);
 
---papi_accrual_object
 
CREATE UNLOGGED TABLE papi_accrual_object (
    spid dsspid,
    objectid dsidentifier,
    objecttypeid dsidentifier,
    finoperid dsidentifier,
    institutionid dsidentifier,
    branchid dsidentifier,
    date dsoperday,
    plandate dsoperday,
    operdate dsoperday,
    creationdate dsdatetime,
    valuedate dsdatetime,
    closedate dsdatetime,
    crnid dsidentifier,
    number dsvarfullname40,
    period dsint_key,
    ntfid dsint_key,
    initialobjectid dsidentifier
);
 
ALTER TABLE ONLY papi_accrual_object
    ADD CONSTRAINT papi_accrual_object_xpkpapi_accrual_object UNIQUE (spid, objectid) DEFERRABLE;
CREATE INDEX papi_accrual_object_xie1papi_accrual_object ON papi_accrual_object USING btree (spid, ntfid, finoperid);
CREATE INDEX papi_accrual_object_xie2papi_accrual_object ON papi_accrual_object USING btree (spid, crnid);
CREATE INDEX papi_accrual_object_xie3papi_accrual_object ON papi_accrual_object USING btree (spid, operdate);
 
--papi_accrual_date
 
CREATE UNLOGGED TABLE papi_accrual_date (
    spid dsspid,
    initialobjectid dsidentifier,
    ntfid dsint_key,
    objectid dsidentifier,
    templatenumber dsidentifier,
    begindate dsoperday,
    enddate dsoperday
);
 
ALTER TABLE ONLY papi_accrual_date
    ADD CONSTRAINT papi_accrual_date_xpkpapi_accrual_date UNIQUE (spid, templatenumber, objectid) DEFERRABLE;
CREATE INDEX papi_accrual_date_xie1papi_accrual_date ON papi_accrual_date USING btree (spid, templatenumber, begindate, enddate);
 
 
----pqtyobjectmember
 
CREATE UNLOGGED TABLE pqtyobjectmember (
    spid dsint_key,
    objectid dsidentifier,
    partnumber dsint_key,
    opertemplateid dsidentifier,
    sumorder dsint_key,
    fundid dsidentifier,
    const dsfloat,
    mult1 dsfloat,
    mult2 dsfloat,
    mult3 dsfloat,
    mult4 dsfloat,
    mult5 dsfloat,
    div1 dsfloat,
    div2 dsfloat,
    div3 dsfloat,
    div4 dsfloat,
    div5 dsfloat
);
 
ALTER TABLE ONLY pqtyobjectmember
    ADD CONSTRAINT pqtyobjectmember_xpkpqtyobjectmember UNIQUE (spid, partnumber, objectid, opertemplateid, sumorder, div1, div2, div3, div4, div5) DEFERRABLE;
    
--palltemplate
   
CREATE UNLOGGED TABLE palltemplate (
    spid dsspid,
    prio dsint_key,
    type dsint_key,
    opertemplateid dsidentifier,
    number dsfieldname,
    security dsidentifier,
    qtyfrmtext dscomment,
    sysname dsbic
);
 
CREATE INDEX palltemplate_xie1palltemplate ON palltemplate USING btree (spid);
CREATE INDEX palltemplate_xie2palltemplate ON palltemplate USING btree (spid, opertemplateid);   
 
---paccr_object_cprotocol
 
CREATE UNLOGGED TABLE paccr_object_cprotocol (
    spid dsspid,
    objectid dsidentifier,
    finoperid dsidentifier,
    currprotocolid dsidentifier
);
 
 
ALTER TABLE ONLY paccr_object_cprotocol
    ADD CONSTRAINT paccr_object_cprotocol_xpkpaccr_object_cprotocol UNIQUE (spid, objectid, finoperid) DEFERRABLE;
 
---palltemplatedoc
   
CREATE UNLOGGED TABLE palltemplatedoc (
    spid dsspid,
    opertemplateid dsidentifier,
    priority dstinyint
);
 
CREATE INDEX palltemplatedoc_xie1palltemplatedoc ON palltemplatedoc USING btree (spid);
CREATE INDEX palltemplatedoc_xie2palltemplatedoc ON palltemplatedoc USING btree (spid, opertemplateid);
 
 
---pdocumenttemplate
 
CREATE UNLOGGED TABLE pdocumenttemplate (
    spid dsspid,
    opertemplateid dsidentifier
);
 
CREATE INDEX pdocumenttemplate_xpkpdocumenttemplate ON pdocumenttemplate USING btree (spid, opertemplateid);
 
---papi_accrual_objaccount
 
CREATE UNLOGGED TABLE papi_accrual_objaccount (
    spid dsspid,
    objectid dsidentifier,
    accountid dsidentifier,
    crnid dsidentifier,
    tmpid dsidentifier,
    tmp2id dsidentifier,
    templatenumber dsidentifier,
    ntfid dsint_key
);
 
ALTER TABLE ONLY papi_accrual_objaccount
    ADD CONSTRAINT papi_accrual_objaccount_xpkpapi_accrual_objaccount UNIQUE (spid, templatenumber, objectid) DEFERRABLE;
CREATE INDEX papi_accrual_objaccount_xie2papi_accrual_objaccount ON papi_accrual_objaccount USING btree (spid, objectid, templatenumber);
CREATE INDEX papi_accrual_objaccount_xie3papi_accrual_objaccount ON papi_accrual_objaccount USING btree (spid, templatenumber, tmp2id);
CREATE INDEX papi_accrual_objaccount_xie4papi_accrual_objaccount ON papi_accrual_objaccount USING btree (spid, objectid, crnid);
 
---papi_cacc_letterauthority
 
CREATE UNLOGGED TABLE papi_cacc_letterauthority (
    spid dsspid,
    currentaccountid dsidentifier,
    letterauthorityid dsidentifier,
    kind dstinyint,
    branchid dsidentifier,
    branchbrief dsaccnumber,
    authorid dsidentifier,
    authorbrief dsusername,
    authorname dsvarfullname160,
    number dsnumber20,
    datecreation dsoperday,
    ownerid dsidentifier,
    ownerkind dstinyint,
    ownerbrief dsusername,
    ownername dsfullname,
    ownericardid dsidentifier,
    ownericardtypebrief dsbriefvar,
    ownericardregnumber dshash,
    ownericardregseries dslabel,
    agentid dsidentifier,
    agentbrief dsusername,
    agentname dsfullname,
    agenticardid dsidentifier,
    agenticardtypebrief dsbriefvar,
    agenticardregnumber dshash,
    agenticardregseries dslabel,
    dateoper dsoperday,
    datestart dsoperday,
    termday dsfloat,
    termmonth dsfloat,
    dateend dsoperday,
    status dstinyint,
    comment dscomment,
    finoperid dsidentifier,
    stateid dsidentifier,
    statebrief dsbriefname,
    statename dsfullname
);
 
CREATE INDEX papi_cacc_letterauthority_xie1papi_cacc_letterauthority ON papi_cacc_letterauthority USING btree (spid, currentaccountid);
 
---ptdpt_jr
 
CREATE UNLOGGED TABLE ptdpt_jr (
    spid dsspid,
    jrelid dsidentifier,
    jrdocid dsidentifier,
    agentid dsidentifier,
    agentkind dstinyint
);
 
CREATE INDEX ptdpt_jr_xpkptdpt_jr ON ptdpt_jr USING btree (spid, jrelid, jrdocid);
 
---papi_jrel_findlist
 
CREATE UNLOGGED TABLE papi_jrel_findlist (
    agent dsaccnumber,
    agentid dsidentifier,
    jrdocfinoper dsbriefname,
    jrdocfinoperid dsidentifier,
    jrdocid dsidentifier,
    jrelid dsidentifier,
    jrole dsbriefname,
    partctype dstinyint,
    spid dsspid,
    status dsbriefname
);
 
CREATE INDEX papi_jrel_findlist_xpkpapi_jrel_findlist ON papi_jrel_findlist USING btree (spid, jrelid);
 
---papi_juraldoc_findlist
 
CREATE UNLOGGED TABLE papi_juraldoc_findlist (
    agenticardid dsidentifier,
    agentid dsidentifier,
    authorid dsidentifier,
    authorname dsvarfullname160,
    branchid dsidentifier,
    comment dscomment,
    dateaccount dsoperday,
    dateclose dsoperday,
    datecreation dsoperday,
    dateoper dsoperday,
    finoperid dsidentifier,
    flallacc dstinyint,
    icardid dsidentifier,
    internalnumber dsaccnumvar,
    jrdocid dsidentifier,
    juraldoctype dstinyint,
    linkid dsidentifier,
    main dstinyint,
    notusedflag dstinyint,
    originalnumber dshash,
    ownerid dsidentifier,
    periodday dsint_key,
    periodmonth dsint_key,
    spid dsspid,
    statebrief dsbriefname,
    type dstinyint,
    typebrief dsbriefname,
    typename dsfullname
);
 
ALTER TABLE ONLY papi_juraldoc_findlist
    ADD CONSTRAINT papi_juraldoc_findlist_xpkpapi_juraldoc_findlist UNIQUE (spid, jrdocid, type) DEFERRABLE;
 
---tdpt_finoper_sync
   
CREATE TABLE tdpt_finoper_sync (
    finoperid dsidentifier NOT NULL,
    parentid dsidentifier NOT NULL,
    initialstateid dsidentifier NOT NULL,
    brief dsbriefname NOT NULL,
    name dsfullname NOT NULL,
    type dsidentifier NOT NULL,
    comment dscomment NOT NULL,
    autocomment dscomment NOT NULL,
    dsmoduleid dsidentifier NOT NULL,
    interfaceobjectid dsidentifier NOT NULL,
    verify dsidentifier NOT NULL,
    haveperiod dstinyint NOT NULL,
    findprconobject dstinyint NOT NULL,
    replicatorscript dscomment NOT NULL
);
 
ALTER TABLE ONLY tdpt_finoper_sync
    ADD CONSTRAINT tdpt_finoper_sync_xpktdpt_finoper_sync UNIQUE (finoperid) DEFERRABLE;
CREATE INDEX tdpt_finoper_sync_xie0tdpt_finoper_sync ON tdpt_finoper_sync USING btree (interfaceobjectid, finoperid);
CREATE INDEX tdpt_finoper_sync_xie1tdpt_finoper_sync ON tdpt_finoper_sync USING btree (((lower((brief)::text))::dsbriefname));
 
---papi_sm_currentstate
 
CREATE UNLOGGED TABLE papi_sm_currentstate (
    spid dsspid,
    editenabled dsidentifier,
    auditid dsidentifier,
    brief dsaccnumber,
    date dsoperday,
    finoperid dsidentifier,
    id dsidentifier,
    incomplete dsint_key,
    name dsfullname,
    objectid dsidentifier,
    objecttypeid dsidentifier,
    protocolid dsidentifier,
    stateid dsidentifier,
    usertype dsidentifier,
    usertypebrief dsbriefvar
);
 
ALTER TABLE ONLY papi_sm_currentstate
    ADD CONSTRAINT papi_sm_currentstate_xpkpapi_sm_currentstate UNIQUE (spid, id, finoperid) DEFERRABLE;
 
---tdpt_partc_sync
 
CREATE TABLE tdpt_partc_sync (
    participantid dsidentifier NOT NULL,
    proptype dstinyint NOT NULL,
    brief dsaccnumber NOT NULL,
    name dsvarfullname160 NOT NULL,
    name1 dsvarfullname160 NOT NULL,
    name2 dsvarfullname160 NOT NULL,
    resident dstinyint NOT NULL,
    inn dsbic NOT NULL,
    countryid dsidentifier NOT NULL,
    country dsaccnumvar NOT NULL,
    portal dsnumber NOT NULL,
    externalid dsidentifier NOT NULL,
    branchid dsidentifier NOT NULL,
    indatetime dsdatetime NOT NULL,
    birthday dsoperday NOT NULL,
    isbankrupt dstinyint
);
 
ALTER TABLE ONLY tdpt_partc_sync
    ADD CONSTRAINT tdpt_partc_sync_xak1tdpt_partc_sync UNIQUE (((lower((brief)::text))::dsaccnumber), proptype) DEFERRABLE;
ALTER TABLE ONLY tdpt_partc_sync
    ADD CONSTRAINT tdpt_partc_sync_xpktdpt_partc_sync UNIQUE (participantid) DEFERRABLE;
 
---papi_prs_icard
   
CREATE UNLOGGED TABLE papi_prs_icard (
    spid dsspid,
    personid dsidentifier,
    doctypeid dsidentifier,
    doctype dsbriefname,
    regnumber dshash,
    regseries dslabel,
    regdepartment dscomment,
    codepasspdepartment dsfieldname,
    dateofissue dsoperday,
    dateregend dsoperday,
    flmain dstinyint,
    fldead dstinyint,
    icardid dsidentifier,
    icardstartdate dsoperday
);
 
CREATE INDEX papi_prs_icard_xie1papi_prs_icard ON papi_prs_icard USING btree (spid, personid);
CREATE INDEX papi_prs_icard_xpkpapi_prs_icard ON papi_prs_icard USING btree (spid, icardid);
 
---tdptlegalclientlink
 
CREATE TABLE tdptlegalclientlink (
    dptlegalclientlinkid dsidentifier NOT NULL,
    objectid dsidentifier NOT NULL,
    legalbaseid dsidentifier NOT NULL,
    instrole dsint_key NOT NULL,
    general dsint_key NOT NULL,
    instchildid dsidentifier NOT NULL,
    issingle dsint_key NOT NULL,
    status dsint_key NOT NULL
);
 
ALTER TABLE ONLY tdptlegalclientlink
    ADD CONSTRAINT tdptlegalclientlink_xpktdptlegalclientlink UNIQUE (dptlegalclientlinkid) DEFERRABLE;
CREATE INDEX tdptlegalclientlink_xie1tdptlegalclientlink ON tdptlegalclientlink USING btree (objectid);
CREATE INDEX tdptlegalclientlink_xie2tdptlegalclientlink ON tdptlegalclientlink USING btree (legalbaseid);
CREATE INDEX tdptlegalclientlink_xie3tdptlegalclientlink ON tdptlegalclientlink USING btree (instchildid, instrole, status);
 
---papi_chacc_fndlstidchange
 
CREATE UNLOGGED TABLE papi_chacc_fndlstidchange (
    spid dsspid,
    chartaccid dsidentifier,
    changekind dstinyint,
    changedate dsdatetime
);
 
CREATE INDEX papi_chacc_fndlstidchange_xpkpapi_chacc_fndlstidchange ON papi_chacc_fndlstidchange USING btree (spid);
 
---taudit
 
CREATE TABLE taudit (
    auditid dsidentifier NOT NULL,
    userid dsidentifier NOT NULL,
    indatetime dsdatetime NOT NULL,
    action dstinyint NOT NULL,
    objectid dsidentifier NOT NULL,
    objectname dsfieldnamevar NOT NULL,
    comment dscomment NOT NULL,
    hostinfoid dsidentifier NOT NULL,
    verified dsbit0 NOT NULL,
    objectreference dsbit0 NOT NULL
);
 
ALTER TABLE ONLY taudit
    ADD CONSTRAINT taudit_xpktaudit UNIQUE (auditid) DEFERRABLE;
 
CREATE INDEX taudit_xie0taudit ON taudit USING btree (userid, indatetime);
CREATE INDEX taudit_xie3taudit ON taudit USING btree (objectid, action);
CREATE INDEX taudit_xie4taudit ON taudit USING btree (indatetime);
 
---tresource
 
CREATE TABLE tresource (
    resourceid dsidentifier NOT NULL,
    balanceid dsidentifier NOT NULL,
    institutionid dsidentifier NOT NULL,
    instownerid dsidentifier NOT NULL,
    fundid dsidentifier NOT NULL,
    securityid dsidentifier NOT NULL,
    secissueid dsidentifier NOT NULL,
    name dscomment NOT NULL,
    brief dsacc_swift NOT NULL,
    parentmask dsvarfullname40 NOT NULL,
    mask dsvarfullname NOT NULL,
    parentid dsidentifier NOT NULL,
    resourcetype dstinyint NOT NULL,
    objectid dsidentifier NOT NULL,
    chartype dstinyint NOT NULL,
    restricttype dstinyint NOT NULL,
    proptype dsidentifier NOT NULL,
    mainacc dssmallint NOT NULL,
    defaultacc dstinyint NOT NULL,
    revaltype dsidentifier NOT NULL,
    blocked dstinyint NOT NULL,
    datestart day NOT NULL,
    dateend dsoperday NOT NULL,
    note dscomment NOT NULL,
    note1 dscomment NOT NULL,
    reshash dslabel NOT NULL,
    accanlid dsidentifier NOT NULL,
    parenthash dslabel NOT NULL,
    accountlength dsidentifier NOT NULL,
    restcheck dsmoney NOT NULL,
    resbenefid dsidentifier NOT NULL,
    instbenefid dsidentifier NOT NULL,
    revalid dsidentifier NOT NULL,
    acclinkedid dsidentifier NOT NULL,
    levelid dsidentifier NOT NULL,
    usermainid dsidentifier NOT NULL,
    userid dsidentifier NOT NULL,
    indatetime dsdatetime NOT NULL,
    dealprotocolid dsidentifier NOT NULL,
    bankcontractnum dsaccnumvar NOT NULL,
    bankcontractdate dsoperday NOT NULL,
    datenotifygni dsoperday NOT NULL,
    datenotifypf dsoperday NOT NULL,
    datenotifyfoms dsoperday NOT NULL,
    isrestcheck dstinyint NOT NULL,
    accorder dsaccnumber NOT NULL,
    keyposition dsidentifier NOT NULL,
    subdivisionid dsidentifier NOT NULL,
    settings dsidentifier NOT NULL,
    ownercontrol dsidentifier NOT NULL,
    clientinstructid dsidentifier NOT NULL,
    altername dscomment NOT NULL,
    accprofileid dsidentifier NOT NULL,
    instrumentid dsidentifier NOT NULL,
    clientcloseinstructid dsidentifier,
    dealcloseprotocolid dsidentifier
);
 
ALTER TABLE ONLY tresource
    ADD CONSTRAINT tresource_xak1tresource UNIQUE (((lower((brief)::text))::dsacc_swift), ((lower((parentmask)::text))::dsvarfullname40), institutionid, fundid, dateend) DEFERRABLE;
ALTER TABLE ONLY tresource
    ADD CONSTRAINT tresource_xak2tresource UNIQUE (resourcetype, balanceid, institutionid, fundid, ((lower((parentmask)::text))::dsvarfullname40), ((lower((brief)::text))::dsacc_swift), dateend) DEFERRABLE;
ALTER TABLE ONLY tresource
    ADD CONSTRAINT tresource_xak3tresource UNIQUE (parentid, institutionid, fundid, ((lower((reshash)::text))::dslabel), dateend) DEFERRABLE;
ALTER TABLE ONLY tresource
    ADD CONSTRAINT tresource_xak4tresource UNIQUE (resourcetype, balanceid, institutionid, ((lower((accorder)::text))::dsaccnumber), dateend) DEFERRABLE;
ALTER TABLE ONLY tresource
    ADD CONSTRAINT tresource_xpktresource UNIQUE (resourceid) DEFERRABLE;
 
CREATE INDEX tresource_xie10tresource ON tresource USING btree (usermainid);
CREATE INDEX tresource_xie11tresource ON tresource USING btree (parentid, institutionid, fundid, ((lower((brief)::text))::dsacc_swift));
CREATE INDEX tresource_xie1tresource ON tresource USING btree (((lower((parenthash)::text))::dslabel));
CREATE INDEX tresource_xie2tresource ON tresource USING btree (instownerid, parentid);
CREATE INDEX tresource_xie3tresource ON tresource USING btree (resbenefid);
CREATE INDEX tresource_xie4tresource ON tresource USING btree (instbenefid, institutionid, fundid);
CREATE INDEX tresource_xie5tresource ON tresource USING btree (parentid, fundid, resourcetype);
CREATE INDEX tresource_xie7tresource ON tresource USING btree (accanlid);
CREATE INDEX tresource_xie8tresource ON tresource USING btree (dealprotocolid);
CREATE INDEX tresource_xie9tresource ON tresource USING btree (institutionid, fundid, defaultacc);
 
---hresource
 
CREATE TABLE hresource (
    historyheaderid dsidentifier NOT NULL,
    resourceid dsidentifier NOT NULL,
    balanceid dsidentifier NOT NULL,
    institutionid dsidentifier NOT NULL,
    instownerid dsidentifier NOT NULL,
    fundid dsidentifier NOT NULL,
    securityid dsidentifier NOT NULL,
    secissueid dsidentifier NOT NULL,
    name dscomment NOT NULL,
    brief dsacc_swift NOT NULL,
    parentmask dsvarfullname40 NOT NULL,
    mask dsvarfullname NOT NULL,
    parentid dsidentifier NOT NULL,
    resourcetype dstinyint NOT NULL,
    objectid dsidentifier NOT NULL,
    chartype dstinyint NOT NULL,
    restricttype dstinyint NOT NULL,
    proptype dsidentifier NOT NULL,
    mainacc dssmallint NOT NULL,
    defaultacc dstinyint NOT NULL,
    revaltype dsidentifier NOT NULL,
    blocked dstinyint NOT NULL,
    datestart day NOT NULL,
    dateend dsoperday NOT NULL,
    note dscomment NOT NULL,
    note1 dscomment NOT NULL,
    reshash dslabel NOT NULL,
    accanlid dsidentifier NOT NULL,
    parenthash dslabel NOT NULL,
    accountlength dsidentifier NOT NULL,
    restcheck dsmoney NOT NULL,
    resbenefid dsidentifier NOT NULL,
    instbenefid dsidentifier NOT NULL,
    revalid dsidentifier NOT NULL,
    acclinkedid dsidentifier NOT NULL,
    levelid dsidentifier NOT NULL,
    usermainid dsidentifier NOT NULL,
    userid dsidentifier NOT NULL,
    indatetime dsdatetime NOT NULL,
    dealprotocolid dsidentifier NOT NULL,
    bankcontractnum dsaccnumvar NOT NULL,
    bankcontractdate dsoperday NOT NULL,
    datenotifygni dsoperday NOT NULL,
    datenotifypf dsoperday NOT NULL,
    datenotifyfoms dsoperday NOT NULL,
    isrestcheck dstinyint NOT NULL,
    accorder dsaccnumber NOT NULL,
    keyposition dsidentifier NOT NULL,
    subdivisionid dsidentifier NOT NULL,
    settings dsidentifier NOT NULL,
    ownercontrol dsidentifier NOT NULL,
    clientinstructid dsidentifier NOT NULL,
    altername dscomment NOT NULL,
    accprofileid dsidentifier NOT NULL,
    instrumentid dsidentifier NOT NULL,
    clientcloseinstructid dsidentifier,
    dealcloseprotocolid dsidentifier
);
 
ALTER TABLE ONLY hresource
    ADD CONSTRAINT hresource_xpkhresource UNIQUE (historyheaderid) DEFERRABLE;
 
--tpoolstorerest
 
CREATE TABLE tpoolstorerest (
    poolstorerestid dsidentifier NOT NULL,
    accountid dsidentifier NOT NULL,
    accrualdate dsoperday NOT NULL,
    qty dsbigmoney NOT NULL,
    currencyid dsidentifier NOT NULL,
    accrualqty dsbigmoney NOT NULL,
    accrualcurrid dsidentifier NOT NULL,
    dealprotid dsidentifier NOT NULL,
    docdealprotid dsidentifier NOT NULL,
    poolid dsidentifier NOT NULL,
    flag dsint_key NOT NULL,
    contractid dsidentifier
);
 
ALTER TABLE ONLY tpoolstorerest
    ADD CONSTRAINT tpoolstorerest_xpktpoolstorerest UNIQUE (poolstorerestid) DEFERRABLE;
 
CREATE INDEX tpoolstorerest_xie1tpoolstorerest ON tpoolstorerest USING btree (dealprotid);
CREATE INDEX tpoolstorerest_xie2tpoolstorerest ON tpoolstorerest USING btree (accrualdate, accountid);
CREATE INDEX tpoolstorerest_xie3tpoolstorerest ON tpoolstorerest USING btree (docdealprotid);
CREATE INDEX tpoolstorerest_xie4tpoolstorerest ON tpoolstorerest USING btree (accountid, accrualdate);
 
---papi_sm_findparamprotocol
 
CREATE UNLOGGED TABLE papi_sm_findparamprotocol (
    spid dsspid,
    actionbrief dsaccnumber,
    actionid dsidentifier,
    actionname dsfullname,
    actiontype dsint_key,
    auditid dsidentifier,
    date dsoperday,
    incomplete dsint_key,
    objectid dsidentifier,
    protocolid dsidentifier,
    stateid dsidentifier,
    stateorder dsint_key
);
 
ALTER TABLE ONLY papi_sm_findparamprotocol
    ADD CONSTRAINT papi_sm_findparamprotocol_xak1papi_sm_findparamprotocol UNIQUE (spid, protocolid) DEFERRABLE;
ALTER TABLE ONLY papi_sm_findparamprotocol
    ADD CONSTRAINT papi_sm_findparamprotocol_xpkpapi_sm_findparamprotocol UNIQUE (spid, objectid, protocolid) DEFERRABLE;
 
---padm_sm_paramobject
 
CREATE UNLOGGED SEQUENCE padm_sm_paramobject_autoid_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
    CYCLE;
 
CREATE UNLOGGED TABLE padm_sm_paramobject (
    spid dsspid,
    objectid dsidentifier,
    id dsidentifier,
    ispfo dstinyint,
    datestart dsoperday,
    dateend dsoperday,
    autoid dsidentifier DEFAULT nextval('padm_sm_paramobject_autoid_seq'::regclass)
);
 
ALTER TABLE ONLY padm_sm_paramobject
    ADD CONSTRAINT padm_sm_paramobject_xpkpadm_sm_paramobject UNIQUE (spid, autoid) DEFERRABLE;
CREATE INDEX padm_sm_paramobject_xak1padm_sm_paramobject ON padm_sm_paramobject USING btree (spid, ispfo, autoid, objectid, datestart, dateend, id);
 
---tnodeattr
 
CREATE TABLE tnodeattr (
    nodeid dsidentifier NOT NULL,
    periodtype dsint_key NOT NULL,
    required dsint_key NOT NULL,
    propval dsint_key NOT NULL,
    priority dsint_key NOT NULL,
    flags dsint_key NOT NULL
);
 
ALTER TABLE ONLY tnodeattr
    ADD CONSTRAINT tnodeattr_xpktnodeattr UNIQUE (nodeid) DEFERRABLE;
 
 
---tprotocolsuspend
 
CREATE TABLE tprotocolsuspend (
    protocolid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tprotocolsuspend
    ADD CONSTRAINT tprotocolsuspend_xpktprotocolsuspend UNIQUE (protocolid) DEFERRABLE;
 
 
---papi_sm_paramobjectaction
 
CREATE UNLOGGED TABLE papi_sm_paramobjectaction (
    spid dsspid,
    actionid dsidentifier,
    actiontype dsint_key
);
 
ALTER TABLE ONLY papi_sm_paramobjectaction
    ADD CONSTRAINT papi_sm_paramobjectaction_xak1papi_sm_paramobjectaction UNIQUE (spid, actiontype, actionid) DEFERRABLE;
 
ALTER TABLE ONLY papi_sm_paramobjectaction
    ADD CONSTRAINT papi_sm_paramobjectaction_xpkpapi_sm_paramobjectaction UNIQUE (spid, actionid, actiontype) DEFERRABLE;
 
---tnode
 
CREATE TABLE tnode (
    nodeid dsidentifier NOT NULL,
    instrumentid dsidentifier NOT NULL,
    configstyleid dsidentifier NOT NULL,
    dealtype dstinyint NOT NULL,
    brief dsbriefname NOT NULL,
    name dsfullname NOT NULL,
    nodetype dstinyint NOT NULL,
    note dsfullname NOT NULL,
    contextid dsidentifier NOT NULL,
    type dsidentifier NOT NULL,
    closed dsidentifier NOT NULL,
    settings dsidentifier NOT NULL,
    statetype dsidentifier
);
 
ALTER TABLE ONLY tnode
    ADD CONSTRAINT tnode_xak0tnode UNIQUE (configstyleid, nodeid) DEFERRABLE;
 
ALTER TABLE ONLY tnode
    ADD CONSTRAINT tnode_xpktnode UNIQUE (nodeid) DEFERRABLE;
 
CREATE INDEX tnode_xie1tnode ON tnode USING btree (contextid, type);
 
---tlegalbase
 
CREATE TABLE tlegalbase (
    legalbaseid dsidentifier NOT NULL,
    instrumentid dsidentifier NOT NULL,
    instparentid dsidentifier NOT NULL,
    instlicenseparentid dsidentifier NOT NULL,
    instchildid dsidentifier NOT NULL,
    instlicensechildid dsidentifier NOT NULL,
    instcompilerid dsidentifier NOT NULL,
    branchid dsidentifier NOT NULL,
    originalnumber dsaccnumvar NOT NULL,
    internalnumber dsaccnumvar NOT NULL,
    datecreation dsoperday NOT NULL,
    dateoperating dsoperday NOT NULL,
    dateaccount dsoperday NOT NULL,
    dateclosing dsoperday NOT NULL,
    comment dscomment NOT NULL
);
 
ALTER TABLE ONLY tlegalbase
    ADD CONSTRAINT tlegalbase_xak0tlegalbase UNIQUE (instrumentid, ((lower((internalnumber)::text))::dsaccnumvar)) DEFERRABLE;
ALTER TABLE ONLY tlegalbase
    ADD CONSTRAINT tlegalbase_xpktlegalbase UNIQUE (legalbaseid) DEFERRABLE;
 
CREATE INDEX tlegalbase_xie1tlegalbase ON tlegalbase USING btree (instparentid);
CREATE INDEX tlegalbase_xie2tlegalbase ON tlegalbase USING btree (instlicenseparentid);
CREATE INDEX tlegalbase_xie3tlegalbase ON tlegalbase USING btree (instchildid);
CREATE INDEX tlegalbase_xie4tlegalbase ON tlegalbase USING btree (instlicensechildid);
CREATE INDEX tlegalbase_xie5tlegalbase ON tlegalbase USING btree (instcompilerid);
CREATE INDEX tlegalbase_xie6tlegalbase ON tlegalbase USING btree (branchid);
 
---
 
CREATE UNLOGGED TABLE papi_lawsuit_notification (
    spid dsspid,
    lawsuitid dsidentifier,
    ntfid dsidentifier,
    ntfmessage dscomment
);
 
ALTER TABLE ONLY papi_lawsuit_notification
    ADD CONSTRAINT papi_lawsuit_notification_xpkpapi_lawsuit_notification UNIQUE (spid, lawsuitid, ntfid) DEFERRABLE;
 
---
 
CREATE UNLOGGED TABLE papi_lawsuit_massupdate (
    spid dsspid,
    lawsuitid dsidentifier,
    branchid dsidentifier,
    branchbrief dsaccnumber,
    lawsuitnumber dsaccnumvar,
    datecreation dsoperday,
    courtid dsidentifier,
    ownerid dsidentifier,
    agentid dsidentifier,
    claimcourtorderdate dsoperday,
    lawsuitcurrency dsbriefname,
    lawsuitamount dsmoney,
    comment dscomment
);
 
ALTER TABLE ONLY papi_lawsuit_massupdate
    ADD CONSTRAINT papi_lawsuit_massupdate_xpkpapi_lawsuit_massupdate UNIQUE (spid, lawsuitid) DEFERRABLE;
 
---
 
CREATE TABLE tinstitution (
    institutionid dsidentifier NOT NULL,
    brief dsaccnumber NOT NULL,
    name character varying(160) NOT NULL,
    name1 character varying(160) NOT NULL,
    name2 character varying(160) NOT NULL,
    countryid dsidentifier NOT NULL,
    instgroupid dsidentifier NOT NULL,
    address1 dscomment NOT NULL,
    address2 dscomment NOT NULL,
    address3 dscomment NOT NULL,
    okohx character varying(40) NOT NULL,
    okpo character varying(40) NOT NULL,
    bic character varying(15) NOT NULL,
    inn character varying(15) NOT NULL,
    insttype dstinyint NOT NULL,
    propdealpart dstinyint NOT NULL,
    phone1 character varying(40) NOT NULL,
    phone2 character varying(40) NOT NULL,
    fax character varying(40) NOT NULL,
    telex character varying(30) NOT NULL,
    swift character varying(15) NOT NULL,
    email character varying(25) NOT NULL,
    sex dstinyint NOT NULL,
    rating dsidentifier NOT NULL,
    poufor dstinyint NOT NULL,
    portal dsnumber NOT NULL,
    parentid dsidentifier NOT NULL,
    typeofuse dsidentifier NOT NULL,
    userid dsidentifier NOT NULL,
    userid1 dsidentifier NOT NULL,
    tradingsysid dsidentifier NOT NULL,
    tradingsysnum character varying(10) NOT NULL,
    partner dstinyint NOT NULL,
    mainmember dstinyint NOT NULL,
    commission dsfloat NOT NULL,
    accrcv character varying(35) NOT NULL,
    accrcv1 character varying(10) NOT NULL,
    resbenefid dsidentifier NOT NULL,
    capital dsmoney NOT NULL,
    doctypeid dsidentifier NOT NULL,
    externalid dsidentifier NOT NULL,
    exportstatus dsidentifier NOT NULL,
    branchnumber character varying(10) NOT NULL,
    instpaytype character(2) NOT NULL,
    region character(2) NOT NULL,
    "real" dstinyint NOT NULL,
    datedel dsoperday NOT NULL,
    instrumentid dsidentifier NOT NULL,
    changedate dsoperday NOT NULL,
    branchid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tinstitution
    ADD CONSTRAINT tinstitution_xak2tinstitution UNIQUE (((lower((brief)::text))::dsaccnumber), propdealpart) DEFERRABLE;
ALTER TABLE ONLY tinstitution
    ADD CONSTRAINT tinstitution_xak3tinstitution UNIQUE (parentid, ((lower((brief)::text))::dsaccnumber), propdealpart) DEFERRABLE;
ALTER TABLE ONLY tinstitution
    ADD CONSTRAINT tinstitution_xpktinstitution UNIQUE (institutionid) DEFERRABLE;
 
CREATE INDEX tinstitution_idx2 ON tinstitution USING btree (((lower((name)::text))::character varying(160)), ((lower((name1)::text))::character varying(160)), ((lower((name2)::text))::character varying(160)));
CREATE INDEX tinstitution_xak1tinstitution ON tinstitution USING btree (propdealpart);
CREATE INDEX tinstitution_xak4tinstitution ON tinstitution USING btree (((lower((portal)::text))::dsnumber));
CREATE INDEX tinstitution_xie1tinstitution ON tinstitution USING btree (((lower((name1)::text))::character varying(160)));
CREATE INDEX tinstitution_xie2tinstitution ON tinstitution USING btree (((lower((bic)::text))::character varying(15)), "real", datedel);
CREATE INDEX tinstitution_xie3tinstitution ON tinstitution USING btree (insttype, ((lower((bic)::text))::character varying(15)));
CREATE INDEX tinstitution_xie4tinstitution ON tinstitution USING btree (((lower((swift)::text))::character varying(15)));
CREATE INDEX tinstitution_xie5tinstitution ON tinstitution USING btree (((lower((inn)::text))::character varying(15)));
CREATE INDEX tinstitution_xie6tinstitution ON tinstitution USING btree (((lower((accrcv1)::text))::character varying(10)));
CREATE INDEX tinstitution_xie7tinstitution ON tinstitution USING btree (branchid, externalid);
CREATE INDEX tinstitution_xie8tinstitution ON tinstitution USING btree (((lower((name)::text))::character varying(160)));
CREATE INDEX tinstitution_xie9tinstitution ON tinstitution USING btree (countryid);
 
---
 
CREATE UNLOGGED TABLE pgna_findlistbyparam (
    spid dsspid,
    linkid dsidentifier,
    typeacclinkid dsidentifier,
    cnttypeacclink integer,
    linkcrnid dsidentifier,
    residentflag dstinyint,
    branchid dsidentifier
);
 
ALTER TABLE ONLY pgna_findlistbyparam
    ADD CONSTRAINT pgna_findlistbyparam_xpkpgna_findlistbyparam UNIQUE (spid, linkid, linkcrnid, typeacclinkid, residentflag) DEFERRABLE;
 
---
 
CREATE UNLOGGED TABLE papi_gna_param (
    spid dsspid,
    branchbrief dsaccnumber,
    branchid dsidentifier,
    date dsoperday,
    linkcrnid dsidentifier,
    linkcrnnumber dsbriefname,
    linkid dsidentifier,
    reltype dstinyint,
    reltypeid dsidentifier,
    systypebrief dsbriefname,
    systypeid dsidentifier,
    typebrief dsbriefname,
    typeid dsidentifier,
    residentflag dstinyint,
    linkbranchid dsidentifier
);
 
ALTER TABLE ONLY papi_gna_param
    ADD CONSTRAINT papi_gna_param_xpkpapi_gna_param UNIQUE (spid, linkid) DEFERRABLE;
 
 
---
 
CREATE UNLOGGED TABLE papi_finoper_findlst (
    spid dsspid,
    finoperid dsidentifier,
    parentid dsidentifier,
    initialstateid dsidentifier,
    brief dsbriefname,
    name dsfullname,
    type dsidentifier,
    comment dscomment,
    autocomment dscomment,
    dsmoduleid dsidentifier,
    interfaceobjectid dsidentifier,
    verify dsidentifier,
    isdefault dsidentifier,
    clearcheck dsidentifier,
    haveperiod dstinyint,
    transitionmode dsidentifier,
    findprconobject dstinyint,
    replicatorscript dscomment
);
 
CREATE INDEX papi_finoper_findlst_xpkpapi_finoper_findlst ON papi_finoper_findlst USING btree (spid, finoperid);
 
---
 
CREATE TABLE ttypeacclink (
    typeacclinkid dsidentifier NOT NULL,
    reltype dsidentifier NOT NULL,
    objectid dsidentifier NOT NULL,
    name dslabel NOT NULL,
    brief dsaccnumber NOT NULL,
    acctype dsidentifier NOT NULL,
    accmain dsidentifier NOT NULL,
    accowner dsint_key NOT NULL,
    accbalance dsint_key NOT NULL,
    nodeid dsidentifier NOT NULL,
    comment dscomment NOT NULL,
    linktype dsidentifier NOT NULL,
    isresident dsidentifier NOT NULL,
    autoopen dsidentifier NOT NULL,
    branchid dsidentifier NOT NULL,
    fundid dsidentifier NOT NULL,
    objclassifierid dsidentifier NOT NULL,
    objclassifier2id dsidentifier NOT NULL,
    insttype dsidentifier NOT NULL,
    chartype dstinyint NOT NULL,
    balanceid dsidentifier NOT NULL,
    accountfundid dsidentifier NOT NULL,
    maskaccountpicture dsvarfullname NOT NULL,
    maskaccountname dscomment NOT NULL,
    acctypeid dsidentifier NOT NULL,
    isactive dssmallint NOT NULL,
    datefrom dsdatetime NOT NULL,
    dateto dsdatetime NOT NULL,
    flags dsint_key NOT NULL,
    algorithm1 dstinyint NOT NULL,
    algorithm2 dstinyint NOT NULL,
    accprofileid dsidentifier NOT NULL,
    rating dsidentifier NOT NULL,
    algfindaccprofile dsint_key NOT NULL,
    formbelong dsint_key NOT NULL,
    modulealgorithm1 dsint_key NOT NULL,
    modulealgorithm2 dsint_key NOT NULL,
    defusermain dsint_key NOT NULL,
    usermainid dsidentifier NOT NULL,
    linkedpersonalpartid dsidentifier,
    linkedtypeacclinkid dsidentifier,
    ownerkinddetail dstinyint
);
 
ALTER TABLE ONLY ttypeacclink
    ADD CONSTRAINT ttypeacclink_xpktinstracclink UNIQUE (typeacclinkid) DEFERRABLE;
 
CREATE INDEX ttypeacclink_xie0tinstracclink ON ttypeacclink USING btree (reltype, objectid);
CREATE INDEX ttypeacclink_xie1ttypeacclink ON ttypeacclink USING btree (nodeid);
CREATE INDEX ttypeacclink_xie2ttypeacclink ON ttypeacclink USING btree (reltype, linktype, acctype, objectid);
CREATE INDEX ttypeacclink_xie3ttypeacclink ON ttypeacclink USING btree (reltype, linktype, objectid, autoopen);
   
---
 
CREATE TABLE tlinkedacctype (
    linkedacctypeid dsidentifier NOT NULL,
    brief dsbriefname NOT NULL,
    name dsvarfullname40 NOT NULL,
    propval dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tlinkedacctype
    ADD CONSTRAINT tlinkedacctype_xpktlinkedacctype UNIQUE (linkedacctypeid) DEFERRABLE;
 
CREATE INDEX tlinkedacctype_xie1tlinkedacctype ON tlinkedacctype USING btree (propval);
CREATE INDEX tlinkedacctype_xie2tlinkedacctype ON tlinkedacctype USING btree (((lower((brief)::text))::dsbriefname));
 
---
 
CREATE UNLOGGED TABLE papi_gna_fndlstbyparamntf (
    spid dsspid,
    linkid dsidentifier,
    ntfid dsidentifier,
    ntfmessage dscomment
);
 
ALTER TABLE ONLY papi_gna_fndlstbyparamntf
    ADD CONSTRAINT papi_gna_fndlstbyparamntf_xpkpapi_gna_fndlstbyparamntf UNIQUE (spid, linkid) DEFERRABLE;
 
---
 
CREATE UNLOGGED TABLE papi_prmd_attriblist (
    spid dsspid,
    prmdid dsidentifier,
    documenttype dstinyint,
    number dsaccnumvar,
    date dsoperday,
    operationdate dsoperday,
    batchbrief dsbriefname,
    documentgroupbrief dsbriefname,
    documentgroupid dsidentifier,
    debitaccountnumber dsacc_swift,
    debitaccountid dsidentifier,
    creditaccountnumber dsacc_swift,
    creditaccountid dsidentifier,
    debitcurrencyid dsidentifier,
    creditcurrencyid dsidentifier,
    creditamount dsbigmoney,
    debitamount dsbigmoney,
    finoperbrief dsbriefname,
    finoperid dsidentifier,
    userid dsidentifier,
    status dstinyint,
    purpose dscomment,
    statebrief dsbriefname,
    stateid dsidentifier,
    parentdocumentid dsidentifier,
    maindocumentid dsidentifier,
    branchid dsidentifier,
    linkid dsidentifier,
    branchbrief dsaccnumvar,
    batchid dsidentifier,
    creditcurrencybrief dsbriefvar,
    debitcurrencybrief dsbriefvar,
    indatetime dsdatetime,
    nettqty dsmoney,
    uniquecode dsacc_swift,
    parentdocfileid dsidentifier
);
 
CREATE INDEX papi_prmd_attriblist_xie1papi_prmd_attriblist ON papi_prmd_attriblist USING btree (spid, linkid);
CREATE INDEX papi_prmd_attriblist_xie2papi_prmd_attriblist ON papi_prmd_attriblist USING btree (spid, debitaccountid);
CREATE INDEX papi_prmd_attriblist_xie3papi_prmd_attriblist ON papi_prmd_attriblist USING btree (spid, creditaccountid);
CREATE INDEX papi_prmd_attriblist_xpkpapi_prmd_attriblist ON papi_prmd_attriblist USING btree (spid, prmdid);
 
---
 
CREATE UNLOGGED TABLE papi_cashorder_cashsymbol (
    spid dsspid,
    cashorderid dsidentifier,
    number dsaccnumber,
    amount dsmoney,
    purpose dscomment,
    cashsymbolid dsidentifier,
    symboltypeflag dstinyint,
    reportflag dstinyint
);
 
CREATE INDEX papi_cashorder_cashsymbol_xie1papi_cashorder_cashsymbol ON papi_cashorder_cashsymbol USING btree (spid, cashorderid);
CREATE INDEX papi_cashorder_cashsymbol_xpkpapi_cashorder_cashsymbol ON papi_cashorder_cashsymbol USING btree (spid);
 
---
 
CREATE TABLE tdptaccountlink (
    dptaccountlinkid dsidentifier NOT NULL,
    objectid dsidentifier NOT NULL,
    ruleaccid dsidentifier NOT NULL,
    ondate dsoperday NOT NULL,
    accountid dsidentifier NOT NULL,
    datelast dsdatetime NOT NULL,
    currencyid dsidentifier NOT NULL,
    flags dsint_key NOT NULL,
    datestartaccount dsoperday NOT NULL,
    dateendaccount dsoperday NOT NULL,
    briefaccount dsacc_swift NOT NULL,
    currencylinkid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tdptaccountlink
    ADD CONSTRAINT tdptaccountlink_xpktdptaccountlink UNIQUE (dptaccountlinkid) DEFERRABLE;
 
CREATE INDEX tdptaccountlink_xie1tdptaccountlink ON tdptaccountlink USING btree (objectid, ruleaccid);
CREATE INDEX tdptaccountlink_xie2tdptaccountlink ON tdptaccountlink USING btree (accountid, ruleaccid, objectid);
CREATE INDEX tdptaccountlink_xie3tdptaccountlink ON tdptaccountlink USING btree (((lower((briefaccount)::text))::dsacc_swift));
 
---
 
CREATE UNLOGGED TABLE pdpt_objectbytype (
    spid dsspid,
    type dsint_key,
    id dsidentifier
);
 
ALTER TABLE ONLY pdpt_objectbytype
    ADD CONSTRAINT pdpt_objectbytype_xpkpdpt_objectbytype UNIQUE (spid, id, type) DEFERRABLE;
 
---
 
CREATE UNLOGGED TABLE papi_ruledoc_csordsubaccount (
    spid dsspid,
    amount dsbigmoney,
    linkid dsidentifier,
    number dsint_key,
    text dscomment
);
 
CREATE INDEX papi_ruledoc_csordsubaccount_xie1papi_ruledoc_csordsubacc ON papi_ruledoc_csordsubaccount USING btree (spid, linkid);
 
---
 
CREATE UNLOGGED TABLE pgaapallsubcontoresource (
    spid dsspid,
    id dsidentifier,
    chartype dssmallint,
    resourceid dsidentifier,
    countsubconto dstinyint,
    opertemplateid dsidentifier,
    depid1 dsidentifier,
    depid2 dsidentifier,
    depid3 dsidentifier,
    depid4 dsidentifier,
    depid5 dsidentifier,
    depid6 dsidentifier
);
 
ALTER TABLE ONLY pgaapallsubcontoresource
    ADD CONSTRAINT pgaapallsubcontoresource_xak1allsubcontoresource UNIQUE (spid, chartype, id) DEFERRABLE;
 
CREATE INDEX pgaapallsubcontoresource_xie1allsubcontoresource ON pgaapallsubcontoresource USING btree (spid, chartype, countsubconto);
 
---
 
CREATE TABLE tdepartment (
    departmentid dsidentifier NOT NULL,
    name dshash NOT NULL,
    brief dsaccnumber NOT NULL,
    parentid dsidentifier NOT NULL,
    deptype dstinyint NOT NULL,
    subcontotype dsidentifier NOT NULL,
    objectid dsidentifier NOT NULL,
    datestart dsoperday NOT NULL,
    dateend dsoperday NOT NULL,
    dephash dshash NOT NULL,
    depkey dsvarfullname40 NOT NULL,
    blocked dstinyint NOT NULL
);
 
ALTER TABLE ONLY tdepartment
    ADD CONSTRAINT tdepartment_xak1tdepartment UNIQUE (((lower((depkey)::text))::dsvarfullname40)) DEFERRABLE;
ALTER TABLE ONLY tdepartment
    ADD CONSTRAINT tdepartment_xak2tdepartment UNIQUE (parentid, ((lower((brief)::text))::dsaccnumber)) DEFERRABLE;
ALTER TABLE ONLY tdepartment
    ADD CONSTRAINT tdepartment_xak3tdepartment UNIQUE (((lower((brief)::text))::dsaccnumber), subcontotype) DEFERRABLE;
ALTER TABLE ONLY tdepartment
    ADD CONSTRAINT tdepartment_xpktdepartment UNIQUE (departmentid) DEFERRABLE;
CREATE INDEX tdepartment_xie1tdepartment ON tdepartment USING btree (subcontotype, objectid);
CREATE INDEX tdepartment_xie2tdepartment ON tdepartment USING btree (((lower((dephash)::text))::dshash));
 
---
 
CREATE DOMAIN public.dscomment300 AS character varying(300) DEFAULT ''::character varying;
 
CREATE UNLOGGED SEQUENCE pdoccas_pdoccasid_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
    CYCLE;
 
 
CREATE UNLOGGED TABLE pdoccas (
    spid dsspid,
    protocolid dsidentifier,
    pdoccasid dsidentifier DEFAULT nextval('pdoccas_pdoccasid_seq'::regclass),
    instrumentid dsidentifier,
    dealid dsidentifier,
    parentid dsidentifier,
    initiatorid dsidentifier,
    doclinkid dsidentifier,
    docnumber character varying(20),
    batchid dsidentifier,
    opcode dsidentifier,
    date timestamp(0) without time zone,
    confirmed smallint,
    qtydeb numeric(20,4),
    qtycre numeric(20,4),
    course double precision,
    rescompensid dsidentifier,
    docdate timestamp(0) without time zone,
    comment dscomment,
    resdebid dsidentifier,
    rescreid dsidentifier,
    flag character(25),
    reskartid dsidentifier,
    termdate timestamp(0) without time zone,
    contract character varying(25),
    valuedate timestamp(0) without time zone,
    groupdocumentid dsidentifier,
    knf character varying(6),
    modecashplan integer,
    cashplan1 integer,
    cashqty1 numeric(20,4),
    cashprim1 dscomment,
    cashplan2 integer,
    cashqty2 numeric(20,4),
    cashprim2 dscomment,
    cashplan3 integer,
    cashqty3 numeric(20,4),
    cashprim3 dscomment,
    cashid dsidentifier,
    cashclientid dsidentifier,
    cashclientname1 character(35),
    cashclientname2 character(35),
    cashclientname3 character(35),
    cashclientsignresident dsidentifier,
    cashdoctypeid dsidentifier,
    cashdocseries character(35),
    cashdocnumber character(35),
    cashdocdate timestamp(0) without time zone,
    cashdocplace dscomment,
    cashauthority dsidentifier,
    cashsecurityid dsidentifier,
    cashsecpart character(35),
    cashsecnumber integer,
    cashsecsignblank dsidentifier,
    cashprintbasis dscomment,
    resincomid dsidentifier,
    servicevariantid dsidentifier,
    comissbankresclientid dsidentifier,
    comissbankresincomid dsidentifier,
    comissbankqty numeric(20,4),
    comissbankfundid dsidentifier,
    autonumber integer,
    dealprotocolid dsidentifier,
    dispatchparam integer,
    swiftid dsidentifier,
    modeattr integer,
    noregenerate integer,
    docmode integer,
    priority dsidentifier,
    opertemplateid dsidentifier,
    objectid dsidentifier,
    instrumentobjectid dsidentifier,
    clientlicenseid dsidentifier,
    citizenship dsaccnumvar,
    inn dsaccnumvar,
    resreceiver character varying(35),
    receiverkpp dsbriefvar,
    receiverokato dsaccnumvar,
    receiverbankbic dsbic,
    receivername dscomment300,
    receiverinn dsaccnumvar,
    country dsaccnumvar,
    city dsvarfullname,
    birthdate dsoperday,
    address dscomment,
    transitflag dstinyint,
    receiveraccbank character varying(35),
    juraldocid dsidentifier,
    authorid dsidentifier
);
 
CREATE INDEX pdoccas_xpkpdoccas ON pdoccas USING btree (spid, protocolid);
 
---
 
CREATE TABLE tcurrency (
    currencyid dsidentifier NOT NULL,
    name dscomment NOT NULL,
    brief dsaccnumber NOT NULL,
    number dsbriefname NOT NULL,
    isonumber dsbriefname NOT NULL,
    cashbrief dsbriefname NOT NULL,
    scale dsint_key NOT NULL,
    countdayyear dsint_key NOT NULL,
    namehi1 dsusername NOT NULL,
    namehi24 dsusername NOT NULL,
    namehi5 dsusername NOT NULL,
    namelo1 dsusername NOT NULL,
    namelo24 dsusername NOT NULL,
    namelo5 dsusername NOT NULL,
    flags dsint_key NOT NULL,
    instrumentid dsidentifier NOT NULL,
    ratetype dsint_key
);
 
ALTER TABLE ONLY tcurrency
    ADD CONSTRAINT tcurrency_xak1tcurrency UNIQUE (((lower((brief)::text))::dsaccnumber)) DEFERRABLE;
ALTER TABLE ONLY tcurrency
    ADD CONSTRAINT tcurrency_xpktcurrency UNIQUE (currencyid) DEFERRABLE;
CREATE INDEX tcurrency_xie1tcurrency ON tcurrency USING btree (((lower((number)::text))::dsbriefname));
CREATE INDEX tcurrency_xie2tcurrency ON tcurrency USING btree (((lower((cashbrief)::text))::dsbriefname));
CREATE INDEX tcurrency_xie3tcurrency ON tcurrency USING btree (((lower((isonumber)::text))::dsbriefname));
 
---
 
CREATE UNLOGGED TABLE preslist (
    spid dsspid,
    resourceid dsidentifier,
    date dsoperday,
    dephash dshash,
    turndeb dsbigmoney,
    turncre dsbigmoney,
    turndebbs dsbigmoney,
    turncrebs dsbigmoney,
    rest dsbigmoney,
    restbs dsbigmoney,
    securityid dsidentifier,
    portfolioid dsidentifier,
    fundid dsidentifier,
    lastdate dsoperday,
    departmentid dsidentifier,
    restfict dsbigmoney,
    turndebfict dsbigmoney,
    turncrefict dsbigmoney,
    balanceid dsidentifier,
    institutionid dsidentifier
);
 
ALTER TABLE ONLY preslist
    ADD CONSTRAINT preslist_xpkpreslist UNIQUE (spid, resourceid, date, ((lower((dephash)::text))::dshash)) DEFERRABLE;
CREATE INDEX preslist_xie1preslist ON preslist USING btree (spid, balanceid, institutionid, resourceid, date);
CREATE INDEX preslist_xie2preslist ON preslist USING btree (spid, portfolioid);
CREATE INDEX preslist_xie3preslist ON preslist USING btree (spid, date, resourceid, fundid);
 
---
 
CREATE TABLE tgl_userright_sync (
    userid dsidentifier NOT NULL,
    righttype dsidentifier NOT NULL,
    objectid dsidentifier NOT NULL
);
 
ALTER TABLE ONLY tgl_userright_sync
    ADD CONSTRAINT tgl_userright_sync_xpktgl_userright_sync UNIQUE (userid, righttype, objectid) DEFERRABLE;
CREATE INDEX tgl_userright_sync_xietgl_userright_sync ON tgl_userright_sync USING btree (righttype, objectid);
 
 
---
 
CREATE TABLE pTmp_UserPost (
postid numeric (15, 0)
);
 
---
 
CREATE TABLE tuserres (
    userid dsidentifier NOT NULL,
    userrestype dsidentifier NOT NULL,
    resourceid dsidentifier NOT NULL,
    accesstype dsint_key NOT NULL,
    inuserid dsidentifier NOT NULL,
    indatetime dsdatetime NOT NULL
);
 
ALTER TABLE ONLY tuserres
    ADD CONSTRAINT tuserres_xpktuserres UNIQUE (userid, userrestype, resourceid) DEFERRABLE;
CREATE INDEX tuserres_xie1tuserres ON tuserres USING btree (userrestype, resourceid);
 
---
 
CREATE TABLE tresourcebind (
    parentid dsidentifier NOT NULL,
    childid dsidentifier NOT NULL,
    parentdepth dsint_key NOT NULL,
    childdepth dsint_key NOT NULL,
    childrestype dstinyint NOT NULL
);
 
ALTER TABLE ONLY tresourcebind
    ADD CONSTRAINT tresourcebind_xak1tresourcebind UNIQUE (childid, parentid) DEFERRABLE;
ALTER TABLE ONLY tresourcebind
    ADD CONSTRAINT tresourcebind_xpktresourcebind UNIQUE (parentid, childid) DEFERRABLE;
CREATE INDEX tresourcebind_xie1tresourcebind ON tresourcebind USING btree (parentid, childdepth);
CREATE INDEX tresourcebind_xie2tresourcebind ON tresourcebind USING btree (childid, parentdepth);
CREATE INDEX tresourcebind_xie3tresourcebind ON tresourcebind USING btree (parentid, childrestype);
 
---
 
CREATE UNLOGGED TABLE prko_f251_docum (
    spid dsspid,
    dealtransactid dsidentifier,
    debid dsidentifier,
    creid dsidentifier,
    qty dsmoney,
    fixqty dsmoney,
    iscur dstinyint,
    opcode dsint_key,
    batchid dsidentifier,
    eldoc2 dstinyint,
    eldoc3 dstinyint,
    isclientbank dstinyint,
    date dsoperday,
    operid dsidentifier,
    isinc dstinyint,
    datecurs dsoperday,
    instrflags dsint_key,
    opcnt dsint_key
);
 
CREATE INDEX prko_f251_docum_xie1prko_f251_docum ON prko_f251_docum USING btree (spid, instrflags, opcode);
CREATE INDEX prko_f251_docum_xie2prko_f251_docum ON prko_f251_docum USING btree (spid, dealtransactid, instrflags);
CREATE INDEX prko_f251_docum_xie3prko_f251_docum ON prko_f251_docum USING btree (spid, operid);
CREATE INDEX prko_f251_docum_xie4prko_f251_docum ON prko_f251_docum USING btree (spid, instrflags, debid, creid, opcode, batchid);
CREATE INDEX prko_f251_docum_xpkprko_f251_docum ON prko_f251_docum USING btree (spid, instrflags, dealtransactid, operid);
 
---
 
CREATE UNLOGGED TABLE prkocomiss_docterm (
    spid dsspid,
    resourceid dsidentifier NOT NULL,
    instreltypeid dsidentifier NOT NULL,
    resourcefundid dsidentifier NOT NULL,
    clientid dsidentifier NOT NULL,
    institutionid dsidentifier NOT NULL,
    maxdate timestamp(0) without time zone,
    nonfundid dsidentifier,
    interestvalueid dsidentifier,
    interestid dsidentifier,
    fixqty dsidentifier,
    fixcomissfundid dsidentifier,
    accountmethodid dsidentifier,
    flagaccrual integer,
    prcnt dsfloat
);
 
CREATE INDEX prkocomiss_docterm_xie0prkocomiss_docterm ON prkocomiss_docterm USING btree (spid, resourceid, accountmethodid);
 
---
 
CREATE UNLOGGED TABLE prkoresource (
    spid dsspid,
    resourceid dsidentifier,
    num dstinyint,
    depid1 dsidentifier,
    depid2 dsidentifier,
    depid3 dsidentifier,
    depid4 dsidentifier,
    depid5 dsidentifier
);
 
ALTER TABLE ONLY prkoresource
    ADD CONSTRAINT prkoresource_xpkprkoresource UNIQUE (spid, resourceid, num) DEFERRABLE;
 
 
---
 
CREATE UNLOGGED TABLE papi_oper_fndlstbylstacc (
    accountcreditid dsidentifier,
    accountdebitid dsidentifier,
    accountnumbercredit dsacc_swift,
    accountnumberdebit dsacc_swift,
    amountbs dsbigmoney,
    amountcredit dsbigmoney,
    amountdebit dsbigmoney,
    batchid dsidentifier,
    comment dscomment,
    course dsfloat,
    linkid dsidentifier,
    number dsaccnumber,
    operationid dsidentifier,
    opercode dstinyint,
    operdate dsoperday,
    spid dsspid,
    status dstinyint
);
 
CREATE INDEX papi_oper_fndlstbylstacc_xie1papi_oper_fndlstbylstacc ON papi_oper_fndlstbylstacc USING btree (spid, accountdebitid);
CREATE INDEX papi_oper_fndlstbylstacc_xie2papi_oper_fndlstbylstacc ON papi_oper_fndlstbylstacc USING btree (spid, accountcreditid);
CREATE INDEX papi_oper_fndlstbylstacc_xpkpapi_oper_fndlstbylstacc ON papi_oper_fndlstbylstacc USING btree (spid, operationid, linkid);
 
---
 
CREATE UNLOGGED TABLE papi_accrual_objdate (
    spid dsspid,
    ntfid dsint_key,
    initialobjectid dsidentifier,
    objectid dsidentifier,
    qty dsmoney,
    templatenumber dsint_key,
    begindate dsoperday,
    enddate dsoperday,
    crnid dsidentifier
);
 
CREATE INDEX papi_accrual_objdate_xie1papi_accrual_objdate ON papi_accrual_objdate USING btree (spid, templatenumber, objectid);
CREATE INDEX papi_accrual_objdate_xie2papi_accrual_objdate ON papi_accrual_objdate USING btree (spid, objectid, templatenumber, begindate);
CREATE INDEX papi_accrual_objdate_xpkpapi_accrual_objdate ON papi_accrual_objdate USING btree (spid, objectid);
 
---pdpt_accrual_objdatecorrect
 
CREATE UNLOGGED TABLE pdpt_accrual_objdatecorrect (
    spid dsspid,
    objectid dsidentifier,
    trandate dsoperday,
    minobjectdate dsoperday,
    maxobjectdate dsoperday,
    minrestdate dsoperday,
    ntfid dsint_key
);
 
CREATE INDEX pdpt_accrual_objdatecorrect_xpkpdpt_accrual_objdatecorrect ON pdpt_accrual_objdatecorrect USING btree (spid, objectid);
 
 
---
 
create table tmp_test_1(tt1 numeric);
create table tmp_test_2(tt2 integer);