Skip to content

Commit

Permalink
rebuild-drop, rebuild-rename, create, createview: Reduces number of t…
Browse files Browse the repository at this point in the history
…ransactions.
  • Loading branch information
aamine committed Jun 14, 2016
1 parent ee20b36 commit cd02f4e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
10 changes: 6 additions & 4 deletions jobclass/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

script {|params, script|
script.task(params['data-source']) {|task|
task.drop_force_if params['drop']
task.exec params['table-def']
task.analyze_if params['analyze']
task.grant_if params['grant'], params['dest-table']
task.transaction {
task.drop_force_if params['drop']
task.exec params['table-def']
task.analyze_if params['analyze']
task.grant_if params['grant'], params['dest-table']
}
}
}
}
8 changes: 5 additions & 3 deletions jobclass/createview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

script {|params, script|
script.task(params['data-source']) {|task|
task.drop_view_force_if params['drop']
task.exec params['sql-file']
task.grant_if params['grant'], params['dest-table']
task.transaction {
task.drop_view_force_if params['drop']
task.exec params['sql-file']
task.grant_if params['grant'], params['dest-table']
}
}
}
}
18 changes: 11 additions & 7 deletions jobclass/rebuild-drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@

script {|params, script|
script.task(params['data-source']) {|task|
# CREATE
task.drop_force params['dest-table']
task.exec params['table-def']
task.transaction {
# CREATE
task.drop_force params['dest-table']
task.exec params['table-def']

# INSERT
task.exec params['sql-file']
# INSERT
task.exec params['sql-file']

# VACUUM, ANALYZE, GRANT
# GRANT
task.grant_if params['grant'], params['dest-table']
}

# VACUUM, ANALYZE
task.vacuum_if params['vacuum'], params['vacuum-sort'], params['dest-table']
task.analyze_if params['analyze'], params['dest-table']
task.grant_if params['grant'], params['dest-table']
}
}
}
22 changes: 13 additions & 9 deletions jobclass/rebuild-rename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,26 @@
prev_table = '${dest_table}_old'
work_table = '${dest_table}_wk'

# CREATE
task.drop_force prev_table
task.drop_force work_table
task.exec params['table-def'].replace(/\$\{?dest_table\}?\b/, work_table)
task.transaction {
# CREATE
task.drop_force prev_table
task.drop_force work_table
task.exec params['table-def'].replace(/\$\{?dest_table\}?\b/, work_table)

# INSERT
task.exec params['sql-file'].replace(/\$\{?dest_table\}?\b/, work_table)

# INSERT
task.exec params['sql-file'].replace(/\$\{?dest_table\}?\b/, work_table)
# GRANT
task.grant_if params['grant'], work_table
}

# VACUUM, ANALYZE, GRANT
# VACUUM, ANALYZE
task.vacuum_if params['vacuum'], params['vacuum-sort'], work_table
task.analyze_if params['analyze'], work_table
task.grant_if params['grant'], work_table

# RENAME
task.create_dummy_table '$dest_table'
task.transaction {
task.create_dummy_table '$dest_table'
dest_table = params['dest-table']
task.rename_table dest_table.to_s, "#{dest_table.name}_old"
task.rename_table "#{dest_table}_wk", dest_table.name
Expand Down

0 comments on commit cd02f4e

Please sign in to comment.