Skip to content

Commit ecf8cc6

Browse files
committed
Optimize SQL for refreshing table location information
1 parent 6bd88f6 commit ecf8cc6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/main/java/com/alipay/oceanbase/rpc/location/LocationUtil.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,19 @@ public class LocationUtil {
154154
+ "FROM oceanbase.__all_virtual_proxy_schema A inner join oceanbase.__all_server B on A.svr_ip = B.svr_ip and A.sql_port = B.inner_port "
155155
+ "WHERE tenant_name = ? and database_name=? and table_name = ? and tablet_id = 0";
156156

157-
private static final String PROXY_LOCATION_SQL_PARTITION_V4 = "SELECT /*+READ_CONSISTENCY(WEAK)*/ A.tablet_id as tablet_id, A.svr_ip as svr_ip, A.sql_port as sql_port, "
158-
+ "A.table_id as table_id, A.role as role, A.replica_num as replica_num, A.part_num as part_num, B.svr_port as svr_port, B.status as status, B.stop_time as stop_time "
159-
+ ", A.spare1 as replica_type, D.ls_id as ls_id "
160-
+ "FROM oceanbase.__all_virtual_proxy_schema A inner join oceanbase.__all_server B on A.svr_ip = B.svr_ip and A.sql_port = B.inner_port "
161-
+ "inner join oceanbase.DBA_OB_TENANTS C on C.tenant_name = A.tenant_name "
162-
+ "left join oceanbase.CDB_OB_TABLET_TO_LS D on D.tenant_id = C.tenant_id and D.tablet_id = A.tablet_id "
163-
+ "WHERE C.tenant_name = ? and database_name= ? and table_name = ? and A.tablet_id in ({0}) ";
157+
private static final String PROXY_LOCATION_SQL_PARTITION_V4 = "SELECT /*+READ_CONSISTENCY(WEAK)*/ * FROM ( "
158+
+ " SELECT A.tablet_id as tablet__id, A.svr_ip as svr_ip, A.sql_port as sql_port, A.table_id as table_id, "
159+
+ " A.role as role, A.replica_num as replica_num, A.part_num as part_num, B.svr_port as svr_port, B.status as status, "
160+
+ " B.stop_time as stop_time, A.spare1 as replica_type "
161+
+ " FROM oceanbase.__all_virtual_proxy_schema A "
162+
+ " INNER JOIN oceanbase.__all_server B ON A.svr_ip = B.svr_ip AND A.sql_port = B.inner_port "
163+
+ " WHERE A.tablet_id IN ({0}) AND A.tenant_name = ? AND A.database_name = ? AND A.table_name = ?) AS left_table "
164+
+ "LEFT JOIN ("
165+
+ " SELECT D.ls_id, D.tablet_id "
166+
+ " FROM oceanbase.__all_virtual_tablet_to_ls D "
167+
+ " INNER JOIN oceanbase.DBA_OB_TENANTS C ON D.tenant_id = C.tenant_id "
168+
+ " WHERE C.tenant_name = ? "
169+
+ ") AS right_table ON left_table.tablet__id = right_table.tablet_id;";
164170

165171
private static final String PROXY_FIRST_PARTITION_SQL_V4 = "SELECT /*+READ_CONSISTENCY(WEAK)*/ part_id, part_name, tablet_id, high_bound_val, sub_part_num "
166172
+ "FROM oceanbase.__all_virtual_proxy_partition "
@@ -797,6 +803,7 @@ public static TableEntry getTableEntryLocationFromRemote(Connection connection,
797803
ps.setString(1, key.getTenantName());
798804
ps.setString(2, key.getDatabaseName());
799805
ps.setString(3, key.getTableName());
806+
ps.setString(4, key.getTenantName());
800807
rs = ps.executeQuery();
801808
partitionEntry = getPartitionLocationFromResultSet(tableEntry, rs, partitionEntry);
802809
} catch (Exception e) {

0 commit comments

Comments
 (0)