The code below works but have performance issues when the SQL deletes more than a million rows. It takes a very long time for 2M tables to be deleted approx 1 hr. We don't have control on the sql condition passed to us. Is there a better way to make this run faster?
Apart from this we don't have DB admin access so stored procedures can't be a solution. Any help is greatly appreciated. Thanks
SAMPLE SQL QUERY
DELETE TBL_A WHERE ID IN (SELECT ID FROM TBL_B WHERE 1=1 AND TBL_B.BD < TO_DATE(ADD_MONTHS(SYSDATE, -240)));
DELETE METHOD
public void deleteRows(String table, String condition){
StringBuilder sql = new StringBuilder();
sql.append("DELETE TABLE=:TABLE WHERE CONDITION=:CONDITION ");
try{
transaction = session.beginTransaction();
int rows = session.createSQLQuery(sql.toString()).setParamater("TABLE",TABLE).setParameter("CONDITION",CONDITION).executeUpdate();
transaction.commit();
}
catch{
//logic here
}
}
There's no faster way for this specific "issue". Unfortunately, it is not a performance issue, it is an application design issue.
... BUT ...
You can:
insert /*+ append */ into the replica select * from the original
table with NOT
of the CONDITION
. Truncate
the single replica partition with drop storage
option. More specific answer would require a much more specific question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.