【 使用环境 】测试环境
【 OB 】OceanBase
【 使用版本 】5.7.25-OceanBase_CE-v4.0.0.0社区版
【问题描述】like '%文字%'性能很差,特别在多个表JOIN后。同样数据和表在SQL Server和MySQL都正常
【复现路径】附件中有表结构(字段太多可只保留用作条件的关键字段),采用以下语句查询时,需时9秒+,同样数据和表在SQL Server和MySQL都只要0.几秒。
各表数据量:
R_TenantAssociation.sql数据量355条。
T_Drivers.sql数据量987条。
T_Vehicle.sql数据量59174条。
R_VehDriver.sql数据量252条。
执行的SQL如下:
select D_Id ,A. TenantId , D_DriverCode , D_Name, D_Sex , D_Birthday , D_IdCard , D_BusinessLicense , D_PhotoName , D_Photo , D_National
, D_Phone , D_Address , D_CulturalDegree , D_QualificationsType , D_QualificationsNumber, D_QNFirstGetTime , D_QNLicenseIssuingTime
, D_QNEffectiveTime , D_QNLicenseIssuingOrgan, D_QNEffective , D_ServiceQualityLevel , D_ServiceQualityTime , D_ServiceQualityOrganName
, D_DrivingLicense , D_DrivingLicenseVehType , D_DrivingLicenseGetTime , D_RoadTransportNumber , D_Logout , D_LogoutDate , D_LogoutCause
, D_CompanyID , D_Credit , D_StarLevel, D_EntryTime , D_RecordTime , D_DriverCardNo , D_CustomerCompanyId , D_DriverStatus, D_ZeroDate
, D_GoToWorkTime , D_OffDutyTime , D_MaritalStatus , D_DrivingLicenseStartDate, D_DrivingLicenseEndDate , D_ForeignAbility , D_JobType
, D_WechatQRCode , D_AlipayQRCode,C.V_No
from T_Drivers A Left Join R_VehDriver B On D_Id=VD_DID Left Join T_Vehicle C On VD_VID=V_Id And C.Tenantid = A.TenantId
where (A.TenantId = 10 OR A.TenantId IN (Select TA_TenId From R_TenantAssociation Where TA_VirtualId=1))
And (D_Name like ‘%文%’ Or D_IdCard like ‘%文%’ Or D_Phone like ‘%文%’ OR V_No like ‘%文%’ )
order by D_Name
【问题现象及影响】
查询需时9秒+,甚至超过10秒导致超时。同样数据和表在SQL Server和MySQL都只要0.几秒。explain查询执行计划发现比Mysql多好多步骤。请定位问题并优化,谢谢。
【附件】
test_slow_statement.rar (5.9 KB)