forked from MariaDB/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-cfg.sh
3618 lines (3180 loc) · 103 KB
/
server-cfg.sh
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
#!/usr/bin/env perl
# -*- perl -*-
# Copyright (c) 2000-2006 MySQL AB, 2009 Sun Microsystems, Inc.
# Use is subject to license terms.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; version 2
# of the License.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1335 USA
#
# The configuration file for the DBI/DBD tests on different databases ....
# You will need the DBD module for the database you are running.
# Monty made this bench script and I (Luuk de Boer) rewrote it to DBI/DBD.
# Monty rewrote this again to use packages.
#
# Each database has a different package that has 3 functions:
# new Creates a object with some standard slot
# version Version number of the server
# create Generates commands to create a table
#
#
# First some global functions that help use the packages:
#
sub get_server
{
my ($name,$host,$database,$odbc,$machine,$socket,$connect_options)=@_;
my ($server);
if ($name =~ /mysql/i || $name =~ /mariadb/i)
{ $server=new db_MySQL($host, $database, $machine, $socket,$connect_options); }
elsif ($name =~ /pg/i)
{ $server= new db_Pg($host,$database); }
elsif ($name =~ /msql/i)
{ $server= new db_mSQL($host,$database); }
elsif ($name =~ /solid/i)
{ $server= new db_Solid($host,$database); }
elsif ($name =~ /Empress/i)
{ $server= new db_Empress($host,$database); }
elsif ($name =~ /FrontBase/i)
{ $server= new db_FrontBase($host,$database); }
elsif ($name =~ /Oracle/i)
{ $server= new db_Oracle($host,$database); }
elsif ($name =~ /Access/i)
{ $server= new db_access($host,$database); }
elsif ($name =~ /Informix/i)
{ $server= new db_Informix($host,$database); }
elsif ($name =~ /ms-sql/i)
{ $server= new db_ms_sql($host,$database); }
elsif ($name =~ /sybase/i)
{ $server= new db_sybase($host,$database); }
elsif ($name =~ /Adabas/i) # Adabas has two drivers
{
$server= new db_Adabas($host,$database);
if ($name =~ /AdabasD/i)
{
$server->{'data_source'} =~ s/:Adabas:/:AdabasD:/;
}
}
elsif ($name =~ /DB2/i)
{ $server= new db_db2($host,$database); }
elsif ($name =~ /Mimer/i)
{ $server= new db_Mimer($host,$database); }
elsif ($name =~ /Sapdb/i)
{ $server= new db_sapdb($host,$database); }
elsif ($name =~ /interBase/i)
{ $server= new db_interbase($host,$database); }
else
{
die "Unknown sql server name used: $name\nUse one of: Access, Adabas, AdabasD, Empress, FrontBase, Oracle, Informix, InterBase, DB2, mSQL, MariaDB, Mimer, MS-SQL, MySQL, Pg, Solid, SAPDB or Sybase.\nIf the connection is done trough ODBC the name must end with _ODBC\n";
}
if ($name =~ /_ODBC$/i || defined($odbc) && $odbc)
{
if (! ($server->{'data_source'} =~ /^([^:]*):([^:]+):([^:]*)/ ))
{
die "Can't find databasename in data_source: '" .
$server->{'data_source'}. "'\n";
}
if ($3) {
$server->{'data_source'} = "$1:ODBC:$3";
} else {
$server->{'data_source'} = "$1:ODBC:$database";
}
}
return $server;
}
sub all_servers
{
return ["Access", "Adabas", "DB2", "Empress", "FrontBase", "Oracle",
"Informix", "InterBase", "MariaDB", "Mimer", "mSQL", "MS-SQL", "MySQL",
"Pg","SAPDB", "Solid", "Sybase"];
}
#############################################################################
# First the configuration for MariaDB / MySQL off course :-)
#############################################################################
package db_MySQL;
sub new
{
my ($type,$host,$database,$machine,$socket,$connect_options)= @_;
my $self= {};
my %limits;
bless $self;
$self->{'cmp_name'} = "mysql";
$self->{'data_source'} = "DBI:MariaDB:database=$database;host=$host";
$self->{'data_source'} .= ";mariadb_socket=$socket" if($socket);
$self->{'data_source'} .= ";$connect_options" if($connect_options);
$self->{'limits'} = \%limits;
$self->{'blob'} = "blob";
$self->{'text'} = "text";
$self->{'double_quotes'} = 1; # Can handle: 'Walker''s'
$self->{'vacuum'} = 1; # When using with --fast
$self->{'drop_attr'} = "";
$self->{'transactions'} = 0; # Transactions disabled by default
$limits{'NEG'} = 1; # Supports -id
$limits{'alter_add_multi_col'}= 1; #Have ALTER TABLE t add a int,add b int;
$limits{'alter_table'} = 1; # Have ALTER TABLE
$limits{'alter_table_dropcol'}= 1; # Have ALTER TABLE DROP column
$limits{'alter_table_after'}= 1; # Have ALTER TABLE .. AFTER other_column
$limits{'column_alias'} = 1; # Alias for fields in select statement.
$limits{'func_extra_%'} = 1; # Has % as alias for mod()
$limits{'func_extra_if'} = 1; # Have function if.
$limits{'func_extra_in_num'} = 1; # Has function in
$limits{'func_odbc_floor'} = 1; # Has func_odbc_floor function
$limits{'func_odbc_mod'} = 1; # Have function mod.
$limits{'functions'} = 1; # Has simple functions (+/-)
$limits{'group_by_position'} = 1; # Can use 'GROUP BY 1'
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
$limits{'group_func_extra_std'} = 1; # Have group function std().
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
$limits{'group_functions'} = 1; # Have group functions
$limits{'having_with_alias'} = 1; # Can use aliases in HAVING
$limits{'having_with_group'} = 1; # Can use group functions in HAVING
$limits{'insert_multi_value'} = 1; # Have INSERT ... values (1,2),(3,4)
$limits{'insert_select'} = 1;
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
$limits{'left_outer_join'} = 1; # Supports left outer joins
$limits{'like_with_column'} = 1; # Can use column1 LIKE column2
$limits{'limit'} = 1; # supports the limit attribute
$limits{'truncate_table'} = 1;
$limits{'load_data_infile'} = 1; # Has load data infile
$limits{'lock_tables'} = 1; # Has lock tables
$limits{'max_column_name'} = 64; # max table and column name
$limits{'max_columns'} = 2000; # Max number of columns in table
$limits{'max_conditions'} = 9999; # (Actually not a limit)
$limits{'max_index'} = 16; # Max number of keys
$limits{'max_index_parts'} = 16; # Max segments/key
$limits{'max_tables'} = (($machine || '') =~ "^win") ? 5000 : 65000;
$limits{'max_temporary_tables'}= 400;
$limits{'max_text_size'} = 1000000; # Good enough for tests
$limits{'multi_drop'} = 1; # Drop table can take many tables
$limits{'order_by_position'} = 1; # Can use 'ORDER BY 1'
$limits{'order_by_null'} = 1; # Can use 'ORDER BY NULL'
$limits{'order_by_unused'} = 1;
$limits{'query_size'} = 1000000; # Max size with default buffers.
$limits{'select_without_from'}= 1; # Can do 'select 1';
$limits{'subqueries'} = 0; # Doesn't support sub-queries.
$limits{'table_wildcard'} = 1; # Has SELECT table_name.*
$limits{'unique_index'} = 1; # Unique index works or not
$limits{'working_all_fields'} = 1;
$limits{'working_blobs'} = 1; # If big varchar/blobs works
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
# Some fixes that depends on the environment
if (defined($main::opt_create_options) &&
$main::opt_create_options =~ /engine=heap/i)
{
$limits{'working_blobs'} = 0; # HEAP tables can't handle BLOB's
}
# HEAP is deprecated in favor of MEMORY
if (defined($main::opt_create_options) &&
$main::opt_create_options =~ /engine=memory/i)
{
$limits{'working_blobs'} = 0; # MEMORY tables can't handle BLOB's
}
if (defined($main::opt_create_options) &&
$main::opt_create_options =~ /engine=innodb/i)
{
$self->{'transactions'} = 1; # Transactions enabled
}
if (defined($main::opt_create_options) &&
$main::opt_create_options =~ /engine=bdb/i)
{
$self->{'transactions'} = 1; # Transactions enabled
}
if (defined($main::opt_create_options) &&
$main::opt_create_options =~ /engine=gemini/i)
{
$limits{'working_blobs'} = 0; # Blobs not implemented yet
$limits{'max_tables'} = 500;
$limits{'max_temporary_tables'}= $limits{"max_tables"};
$self->{'transactions'} = 1; # Transactions enabled
}
return $self;
}
#
# Get the version number of the database
#
sub version
{
my ($self)=@_;
my ($dbh,$sth,$version,@row);
$dbh=$self->connect();
$sth = $dbh->prepare("select VERSION()") or die $DBI::errstr;
$version="MySQL 3.20.?";
if ($sth->execute && (@row = $sth->fetchrow_array))
{
$row[0] =~ s/-/ /g; # To get better tables with long names
$version="$row[0]";
}
$sth->finish;
$sth = $dbh->prepare("show status like 'ssl_version'") or die $DBI::errstr;
if ($sth->execute && (@row = $sth->fetchrow_array) && $row[1])
{
$version .= "/$row[1]";
}
$sth->finish;
$dbh->disconnect;
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
return $version;
}
#
# Connection with optional disabling of logging
#
sub connect
{
my ($self)=@_;
my ($dbh);
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
$main::opt_password,{ PrintError => 0}) ||
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
$dbh->do("SET OPTION LOG_OFF=1,UPDATE_LOG=0");
if ($main::opt_connect_command ne "")
{
$dbh->do($main::opt_connect_command) or
die "Can't execute connect_command: $main::opt_connect_command error: $DBI::errstr\n";
}
return $dbh;
}
#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#
# If one uses $main::opt_fast then one is allowed to use
# non standard types to get better speed.
#
sub create
{
my($self,$table_name,$fields,$index,$options) = @_;
my($query,@queries);
if ($main::opt_temporary_tables)
{
$query="create temporary table $table_name (";
}
else
{
$query="create table $table_name (";
}
foreach $field (@$fields)
{
$field =~ s/ big_decimal/ double(10,2)/i;
$query.= $field . ',';
}
foreach $index (@$index)
{
$query.= $index . ',';
}
substr($query,-1)=")"; # Remove last ',';
$query.=" $options" if (defined($options));
$query.=" $main::opt_create_options" if (defined($main::opt_create_options));
push(@queries,$query);
return @queries;
}
sub insert_file {
my ($self,$dbname, $file, $dbh) = @_;
my ($command, $sth);
$file =~ s|\\|/|g; # Change Win32 names to Unix syntax
$command = "load data infile '$file' into table $dbname columns optionally enclosed by '\\'' terminated by ','";
# print "$command\n";
$sth = $dbh->do($command) or die $DBI::errstr;
return $sth; # Contains number of rows
}
#
# Do any conversions to the ANSI SQL query so that the database can handle it
#
sub query {
my($self,$sql) = @_;
return $sql;
}
sub drop_index {
my ($self,$table,$index) = @_;
return "DROP INDEX $index ON $table";
}
#
# Abort if the server has crashed
# return: 0 if ok
# 1 question should be retried
#
sub abort_if_fatal_error
{
return 0;
}
#
# This should return 1 if we to do disconnect / connect when doing
# big batches
#
sub small_rollback_segment
{
return 0;
}
#
# reconnect on errors (needed mainly be crash-me)
#
sub reconnect_on_errors
{
return 0;
}
sub fix_for_insert
{
my ($self,$cmd) = @_;
return $cmd;
}
#
# Optimize tables for better performance
#
sub vacuum
{
my ($self,$full_vacuum,$dbh_ref,@tables)=@_;
my ($loop_time,$end_time,$dbh);
if ($#tables >= 0)
{
$dbh=$$dbh_ref;
$loop_time=new Benchmark;
$dbh->do("OPTIMIZE TABLE " . join(',',@tables)) || die "Got error: $DBI::errstr when executing 'OPTIMIZE TABLE'\n";
$end_time=new Benchmark;
print "Time for book-keeping (1): " .
Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
}
}
#############################################################################
# Definitions for mSQL
#############################################################################
package db_mSQL;
sub new
{
my ($type,$host,$database)= @_;
my $self= {};
my %limits;
bless $self;
$self->{'cmp_name'} = "msql";
$self->{'data_source'} = "DBI:mSQL:$database:$host";
$self->{'limits'} = \%limits;
$self->{'double_quotes'} = 0;
$self->{'drop_attr'} = "";
$self->{'transactions'} = 0; # No transactions
$self->{'blob'} = "text(" . $limits{'max_text_size'} .")";
$self->{'text'} = "text(" . $limits{'max_text_size'} .")";
$limits{'max_conditions'} = 74;
$limits{'max_columns'} = 75;
$limits{'max_tables'} = 65000; # Should be big enough
$limits{'max_temporary_tables'}= $limits{"max_tables"};
$limits{'max_text_size'} = 32000;
$limits{'query_size'} = 65535;
$limits{'max_index'} = 5;
$limits{'max_index_parts'} = 10;
$limits{'max_column_name'} = 35;
$limits{'join_optimizer'} = 0; # Can't optimize FROM tables
$limits{'load_data_infile'} = 0;
$limits{'lock_tables'} = 0;
$limits{'functions'} = 0;
$limits{'group_functions'} = 0;
$limits{'group_distinct_functions'}= 0; # Have count(distinct)
$limits{'multi_drop'} = 0;
$limits{'select_without_from'}= 0;
$limits{'subqueries'} = 0;
$limits{'left_outer_join'} = 0;
$limits{'table_wildcard'} = 0;
$limits{'having_with_alias'} = 0;
$limits{'having_with_group'} = 0;
$limits{'like_with_column'} = 1;
$limits{'order_by_position'} = 1;
$limits{'group_by_position'} = 1;
$limits{'alter_table'} = 0;
$limits{'alter_add_multi_col'}= 0;
$limits{'alter_table_dropcol'}= 0;
$limits{'group_func_extra_std'} = 0;
$limits{'limit'} = 1; # supports the limit attribute
$limits{'unique_index'} = 1; # Unique index works or not
$limits{'insert_select'} = 0;
$limits{'func_odbc_mod'} = 0;
$limits{'func_extra_%'} = 0;
$limits{'func_odbc_floor'} = 0;
$limits{'func_extra_if'} = 0;
$limits{'column_alias'} = 0;
$limits{'NEG'} = 0;
$limits{'func_extra_in_num'} = 0;
$limits{'working_blobs'} = 1; # If big varchar/blobs works
$limits{'order_by_unused'} = 1;
$limits{'working_all_fields'} = 1;
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
return $self;
}
#
# Get the version number of the database
#
sub version
{
my ($tmp,$dir);
foreach $dir ("/usr/local/Hughes", "/usr/local/mSQL","/my/local/mSQL",
"/usr/local")
{
if (-x "$dir/bin/msqladmin")
{
$tmp=`$dir/bin/msqladmin version | grep server`;
if ($tmp =~ /^\s*(.*\w)\s*$/)
{ # Strip pre- and endspace
$tmp=$1;
$tmp =~ s/\s+/ /g; # Remove unnecessary spaces
$tmp .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
return $tmp;
}
}
}
return "mSQL version ???";
}
sub connect
{
my ($self)=@_;
my ($dbh);
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
$main::opt_password,{ PrintError => 0}) ||
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
return $dbh;
}
#
# Can't handle many field types, so we map everything to int and real.
#
sub create
{
my($self,$table_name,$fields,$index) = @_;
my($query,@queries,$name,$nr);
$query="create table $table_name (";
foreach $field (@$fields)
{
$field =~ s/varchar/char/i; # mSQL doesn't have VARCHAR()
# mSQL can't handle more than the real basic int types
$field =~ s/tinyint|smallint|mediumint|integer/int/i;
# mSQL can't handle different visual lengths
$field =~ s/int\(\d*\)/int/i;
# mSQL doesn't have float, change it to real
$field =~ s/float(\(\d*,\d*\)){0,1}/real/i;
$field =~ s/double(\(\d*,\d*\)){0,1}/real/i;
# mSQL doesn't have blob, it has text instead
if ($field =~ / blob/i)
{
$name=$self->{'blob'};
$field =~ s/ blob/ $name/;
}
$query.= $field . ',';
}
substr($query,-1)=")"; # Remove last ',';
push(@queries,$query);
$nr=0;
# Prepend table_name to index name because the the name may clash with
# a field name. (Should be diffent name space, but this is mSQL...)
foreach $index (@$index)
{
# Primary key is unique index in mSQL
$index =~ s/primary key/unique index primary/i;
if ($index =~ /^unique\s*\(([^\(]*)\)$/i)
{
$nr++;
push(@queries,"create unique index ${table_name}_$nr on $table_name ($1)");
}
else
{
if (!($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i))
{
die "Can't parse index information in '$index'\n";
}
push(@queries,"create $1 ${table_name}_$2 on $table_name $3");
}
}
return @queries;
}
sub insert_file {
my($self,$dbname, $file) = @_;
print "insert an ascii file isn't supported by mSQL\n";
return 0;
}
sub query {
my($self,$sql) = @_;
return $sql;
}
sub drop_index
{
my ($self,$table,$index) = @_;
return "DROP INDEX $index FROM $table";
}
sub abort_if_fatal_error
{
return 0;
}
sub small_rollback_segment
{
return 0;
}
sub reconnect_on_errors
{
return 0;
}
sub fix_for_insert
{
my ($self,$cmd) = @_;
return $cmd;
}
#############################################################################
# Definitions for PostgreSQL #
#############################################################################
package db_Pg;
sub new
{
my ($type,$host,$database)= @_;
my $self= {};
my %limits;
bless $self;
$self->{'cmp_name'} = "pg";
$self->{'data_source'} = "DBI:Pg:dbname=$database";
$self->{'limits'} = \%limits;
$self->{'blob'} = "text";
$self->{'text'} = "text";
$self->{'double_quotes'} = 1;
$self->{'drop_attr'} = "";
$self->{'transactions'} = 1; # Transactions enabled
$self->{"vacuum"} = 1;
$limits{'join_optimizer'} = 1; # Can optimize FROM tables
# load_data_infile could use function 'insert_file', but I could not get it to
# work because of permissions problems. Disabling for now.
$limits{'load_data_infile'} = 0;
$limits{'NEG'} = 1;
$limits{'alter_add_multi_col'}= 1;
$limits{'alter_table'} = 1;
$limits{'alter_table_dropcol'}= 1;
$limits{'alter_table_after'} = 0; # Have ALTER TABLE .. AFTER other_column
$limits{'column_alias'} = 1;
$limits{'func_extra_%'} = 1;
$limits{'func_extra_if'} = 0;
$limits{'func_extra_in_num'} = 1;
$limits{'func_odbc_floor'} = 1;
$limits{'func_odbc_mod'} = 1; # Has %
$limits{'functions'} = 1;
$limits{'group_by_position'} = 1;
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
$limits{'group_func_extra_std'} = 0;
$limits{'group_func_sql_min_str'}= 1; # Can execute MIN() and MAX() on strings
$limits{'group_functions'} = 1;
$limits{'having_with_alias'} = 0;
$limits{'having_with_group'} = 1;
$limits{'insert_select'} = 1;
$limits{'left_outer_join'} = 1;
$limits{'like_with_column'} = 1;
$limits{'lock_tables'} = 0; # in ATIS gives this a problem
$limits{'max_column_name'} = 128;
$limits{'max_columns'} = 1000; # 500 crashes pg 6.3
$limits{'max_conditions'} = 9999; # This makes Pg real slow
$limits{'max_index'} = 64; # Big enough
$limits{'max_index_parts'} = 16;
$limits{'max_tables'} = 65000;
$limits{'max_temporary_tables'}= $limits{"max_tables"};
$limits{'max_text_size'} = 65000; # Good enough for test
$limits{'multi_drop'} = 1;
$limits{'order_by_position'} = 1;
$limits{'order_by_unused'} = 1;
$limits{'query_size'} = 16777216;
$limits{'select_without_from'}= 1;
$limits{'subqueries'} = 1;
$limits{'table_wildcard'} = 1;
$limits{'truncate_table'} = 1;
$limits{'unique_index'} = 1; # Unique index works or not
$limits{'working_all_fields'} = 1;
$limits{'working_blobs'} = 1; # If big varchar/blobs works
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
$limits{'insert_multi_value'} = 1; # Have INSERT ... values (1,2),(3,4)
return $self;
}
# couldn't find the option to get the version number
sub version
{
my ($self)=@_;
my ($dbh,$sth,$version,@row);
$dbh=$self->connect();
$sth = $dbh->prepare("select VERSION()") or die $DBI::errstr;
$version="PostgreSQL ?";
if ($sth->execute && (@row = $sth->fetchrow_array))
{
$row[0] =~ s/-/ /g; # To get better tables with long names
$version="PostgreSQL $row[0]";
}
$sth->finish;
$dbh->disconnect;
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
return $version;
}
sub connect
{
my ($self)=@_;
my ($dbh);
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
$main::opt_password,{ PrintError => 0}) ||
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
return $dbh;
}
sub create
{
my($self,$table_name,$fields,$index) = @_;
my($query,@queries,$name,$in,$indfield,$table,$nr);
$query="create table $table_name (";
foreach $field (@$fields)
{
if ($main::opt_fast)
{
# Allow use of char2, char4, char8 or char16
$field =~ s/char(2|4|8|16)/char$1/;
}
# Pg can't handle more than the real basic int types
$field =~ s/tinyint|smallint|mediumint|integer/int/;
# Pg can't handle different visual lengths
$field =~ s/int\(\d*\)/int/;
$field =~ s/float\(\d*,\d*\)/float/;
$field =~ s/ double/ float/;
# Pg doesn't have blob, it has text instead
$field =~ s/ blob/ text/;
$query.= $field . ',';
}
substr($query,-1)=")"; # Remove last ',';
push(@queries,$query);
foreach $index (@$index)
{
if ($index =~ /primary key/ || $index =~ /PRIMARY KEY/)
{
$query= substr($query, 0, length($query)-1) . ", $index )";
next;
}
elsif ($index =~ /^unique.*\(([^\(]*)\)$/i)
{
$indfield=" (" .$1.")";
$in="unique index";
$table="index_$nr"; $nr++;
}
elsif ($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i)
{
# original: $indfield="using btree (" .$1.")";
$indfield=" " .$3;
$in="index";
$table="index_$nr"; $nr++;
}
else
{
die "Can't parse index information in '$index'\n";
}
push(@queries,"create $in ${table_name}_$table on $table_name $indfield");
}
$queries[0]=$query;
return @queries;
}
sub insert_file {
my ($self,$dbname, $file, $dbh) = @_;
my ($command, $sth);
# Syntax:
# copy [binary] <class_name> [with oids]
# {to|from} {<filename>|stdin|stdout} [using delimiters <delim>]
$command = "copy $dbname from '$file' using delimiters ',' QUOTE ''''";
print "$command\n";
$sth = $dbh->do($command) or die $DBI::errstr;
return $sth;
}
sub query {
my($self,$sql) = @_;
return $sql;
}
sub drop_index
{
my ($self,$table,$index) = @_;
return "DROP INDEX $index";
}
sub abort_if_fatal_error
{
return 1 if ($DBI::errstr =~ /sent to backend, but backend closed/i);
return 0;
}
sub small_rollback_segment
{
return 0;
}
sub reconnect_on_errors
{
return 0;
}
sub fix_for_insert
{
my ($self,$cmd) = @_;
return $cmd;
}
sub vacuum
{
my ($self,$full_vacuum,$dbh_ref,@tables)=@_;
my ($loop_time,$end_time,$dbh,$table);
if (defined($full_vacuum))
{
$$dbh_ref->disconnect; $$dbh_ref= $self->connect();
}
$dbh=$$dbh_ref;
$loop_time=new Benchmark;
if ($#tables >= 0)
{
foreach $table (@tables)
{
$dbh->do("vacuum analyze $table") || die "Got error: $DBI::errstr when executing 'vacuum analyze $table'\n";
$dbh->do("vacuum $table") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
}
}
else
{
$dbh->do("vacuum analyze") || die "Got error: $DBI::errstr when executing 'vacuum analyze'\n";
$dbh->do("vacuum") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
}
$end_time=new Benchmark;
print "Time for book-keeping (1): " .
Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
$dbh->disconnect; $$dbh_ref= $self->connect();
}
#############################################################################
# Definitions for Solid
#############################################################################
package db_Solid;
sub new
{
my ($type,$host,$database)= @_;
my $self= {};
my %limits;
bless $self;
$self->{'cmp_name'} = "solid";
$self->{'data_source'} = "DBI:Solid:";
$self->{'limits'} = \%limits;
$self->{'blob'} = "long varchar";
$self->{'text'} = "long varchar";
$self->{'double_quotes'} = 1;
$self->{'drop_attr'} = "";
$self->{'transactions'} = 1; # Transactions enabled
$limits{'max_conditions'} = 9999; # Probably big enough
$limits{'max_columns'} = 2000; # From crash-me
$limits{'max_tables'} = 65000; # Should be big enough
$limits{'max_temporary_tables'}= $limits{"max_tables"};
$limits{'max_text_size'} = 65492; # According to tests
$limits{'query_size'} = 65535; # Probably a limit
$limits{'max_index'} = 64; # Probably big enough
$limits{'max_index_parts'} = 64;
$limits{'max_column_name'} = 80;
$limits{'join_optimizer'} = 1;
$limits{'load_data_infile'} = 0;
$limits{'lock_tables'} = 0;
$limits{'functions'} = 1;
$limits{'group_functions'} = 1;
$limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
$limits{'group_distinct_functions'}= 1; # Have count(distinct)
$limits{'select_without_from'}= 0; # Can do 'select 1' ?;
$limits{'multi_drop'} = 0;
$limits{'subqueries'} = 1;
$limits{'left_outer_join'} = 1;
$limits{'table_wildcard'} = 1;
$limits{'having_with_alias'} = 0;
$limits{'having_with_group'} = 1;
$limits{'like_with_column'} = 1;
$limits{'order_by_position'} = 0; # 2.30.0018 can this
$limits{'group_by_position'} = 0;
$limits{'alter_table'} = 1;
$limits{'alter_add_multi_col'}= 0;
$limits{'alter_table_dropcol'}= 0;
$limits{'group_func_extra_std'} = 0; # Have group function std().
$limits{'func_odbc_mod'} = 1;
$limits{'func_extra_%'} = 0;
$limits{'func_odbc_floor'} = 1;
$limits{'column_alias'} = 1;
$limits{'NEG'} = 1;
$limits{'func_extra_in_num'} = 1;
$limits{'unique_index'} = 1; # Unique index works or not
$limits{'insert_select'} = 1;
$limits{'working_blobs'} = 1; # If big varchar/blobs works
$limits{'order_by_unused'} = 1;
$limits{'working_all_fields'} = 1;
$limits{'multi_distinct'} = 1; # allows select count(distinct a),count(distinct b)..
return $self;
}
#
# Get the version number of the database
#
sub version
{
my ($version,$dir);
$version="Solid version ??";
foreach $dir ($ENV{'SOLIDDIR'},"/usr/local/solid", "/my/local/solid")
{
if ($dir && -e "$dir/bin/solcon")
{
$version=`$dir/bin/solcon -e"ver" $main::opt_user $main::opt_password | grep Server | sed q`;
if ($? == 0)
{
chomp($version);
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
return $version;
}
}
}
$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
return $version;
}
sub connect
{
my ($self)=@_;
my ($dbh);
$dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
$main::opt_password,{ PrintError => 0}) ||
die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
return $dbh;
}
#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#
sub create
{
my($self,$table_name,$fields,$index) = @_;
my($query,@queries,$nr);
$query="create table $table_name (";
foreach $field (@$fields)
{
$field =~ s/mediumint/integer/i;
$field =~ s/ double/ float/i;
# Solid doesn't have blob, it has long varchar
$field =~ s/ blob/ long varchar/;
# $field =~ s/ decimal/ float/i;
# $field =~ s/ big_decimal/ float/i;
# $field =~ s/ date/ int/i;
$query.= $field . ',';
}
substr($query,-1)=")"; # Remove last ',';
push(@queries,$query);
$nr=0;
foreach $index (@$index)
{
if ($index =~ /^primary key/i || $index =~ /^unique/i)
{ # Add to create statement
substr($queries[0],-1,0)="," . $index;
}
else
{
$index =~ /^(.*)\s+(\(.*\))$/;
push(@queries,"create ${1}$nr on $table_name $2");
$nr++;
}
}
return @queries;
}
# there is no sql statement in solid which can do the load from
# an ascii file in the db ... but there is the speedloader program
# an external program which can load the ascii file in the db ...
# the server must be down before using speedloader !!!!
# (in the standalone version)
# it works also with a control file ... that one must be made ....
sub insert_file {
my ($self, $dbname, $file) = @_;
my ($speedcmd);
$speedcmd = '/usr/local/solid/bin/solload';
print "At this moment not supported - solid server must go down \n";
return 0;
}
# solid can't handle an alias in a having statement so
# select test as foo from tmp group by foo having foor > 2
# becomes
# select test as foo from tmp group by foo having test > 2
#
sub query {
my($self,$sql) = @_;
my(@select,$tmp,$newhaving,$key,%change);
if ($sql =~ /having\s+/i)
{
if ($sql =~ /select (.*) from/i)
{
(@select) = split(/,\s*/, $1);
foreach $tmp (@select)
{