Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
e40dbbdc
Commit
e40dbbdc
authored
12 years ago
by
Andy Yates
Browse files
Options
Downloads
Patches
Plain Diff
Switching to using the alter table command after Kieron's suggestion. Seems nice
parent
67eb6a72
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc-scripts/import/sort_feature_table.pl
+23
-24
23 additions, 24 deletions
misc-scripts/import/sort_feature_table.pl
with
23 additions
and
24 deletions
misc-scripts/import/sort_feature_table.pl
+
23
−
24
View file @
e40dbbdc
#!/usr/bin/env perl
# Designed to sort a feature table by seq_region_id
and then start
# Designed to sort a feature table by seq_region_id
, start and end
use
strict
;
use
warnings
;
...
...
@@ -11,7 +11,7 @@ use POSIX qw/strftime/;
my
(
$db_name
,
$db_host
,
$db_user
,
$db_pass
,
$db_port
,
$help
);
my
@tables
;
my
(
$optimise
,
$
dro
p
,
$nolock
);
my
(
$optimise
,
$
nobacku
p
,
$nolock
);
GetOptions
("
db_name|dbname|database=s
"
=>
\
$db_name
,
"
db_host|dbhost|host=s
"
=>
\
$db_host
,
...
...
@@ -21,7 +21,7 @@ GetOptions ("db_name|dbname|database=s" => \$db_name,
'
table|tables=s@
'
=>
\
@tables
,
'
optimise!
'
=>
\
$optimise
,
'
nolock!
'
=>
\
$nolock
,
'
dro
p!
'
=>
\
$
dro
p
,
'
nobacku
p!
'
=>
\
$
nobacku
p
,
"
h|help!
"
=>
\
$help
,
);
...
...
@@ -62,28 +62,13 @@ sub sort_table {
$dba
->
dbc
()
->
do
("
lock tables
${table}
write
");
}
info
("
Creating alternative table and disabling keys
");
$dba
->
dbc
()
->
do
("
create table
${s_table}
like
${table}
");
$dba
->
dbc
()
->
do
("
alter table
${s_table}
disable keys
");
info
("
Sort/insert
");
$dba
->
dbc
()
->
do
("
insert into
${s_table}
select * from
${table}
order by seq_region_id, seq_region_start, seq_region_end
");
info
("
Re-enabling keys
");
$dba
->
dbc
()
->
do
("
alter table
${s_table}
enable keys
");
my
$bak_name
=
_next_name
(
$table
,
$dba
);
info
("
Moving %s to %s
",
$table
,
$bak_name
);
$dba
->
dbc
()
->
do
("
alter table
${table}
rename as
$bak_name
");
info
("
Moving %s to %s
",
$s_table
,
$table
);
$dba
->
dbc
()
->
do
("
alter table
${s_table}
rename as
$table
");
if
(
$drop
)
{
info
("
Dropping table %s
",
$bak_name
);
$dba
->
dbc
()
->
do
("
drop table
$bak_name
");
if
(
!
$nobackup
)
{
backup_table
(
$table
);
}
info
("
Re-ordering table
");
$dba
->
dbc
()
->
do
("
ALTER TABLE
${table}
ORDER BY seq_region_id, seq_region_start, seq_region_end
");
if
(
!
$nolock
)
{
info
("
Unlocking table %s
",
$table
);
$dba
->
dbc
()
->
do
("
unlock tables
");
...
...
@@ -101,6 +86,18 @@ sub optimise_table {
return
;
}
sub
backup_table
{
my
(
$table
,
$dba
)
=
@_
;
my
$bak_name
=
_next_name
(
$table
,
$dba
);
info
("
Backing up table to
$bak_name
");
$dba
->
dbc
()
->
do
("
create table
${bak_name}
like
${table}
");
$dba
->
dbc
()
->
do
("
alter table
${bak_name}
disable keys
");
$dba
->
dbc
()
->
do
("
insert into
${bak_name}
select * from
${table}
");
$dba
->
dbc
()
->
do
("
alter table
${bak_name}
enable keys
");
info
("
Finished backing up
");
return
$bak_name
;
}
sub
_next_name
{
my
(
$table
,
$dba
)
=
@_
;
my
$count
=
0
;
...
...
@@ -165,7 +162,9 @@ Options:
-optimise Optimise the table post sort
-drop Drop the original table post sort
-nobackup Do not backup the original table
-nolock Stop the code from applying for table locks
-help
";
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment