mysql查询锁定一切

时间:2014-04-04 16:15:18

标签: mysql

用户有一个查询,在运行时锁定数据库中的所有其他内容。 我运行了一个配置文件,它返回了很多记录,但我真的不知道如何处理它。 有人可能更有效地编码吗?它运行了很长一段时间。

SELECT

CLAIMS.LINE_GROUPING1

,CLAIMS.LOSS_DATE

,(CASE WHEN CLAIMS.POLICY_STATE=14 THEN 'IA'

WHEN CLAIMS.POLICY_STATE=12 THEN 'IL'

WHEN CLAIMS.POLICY_STATE=22 THEN 'MN'

WHEN CLAIMS.POLICY_STATE=26 THEN 'NE'

WHEN CLAIMS.POLICY_STATE=40 THEN 'SD'

WHEN CLAIMS.POLICY_STATE=48 THEN 'WI'

ELSE 'NA' END) AS POLICY_STATE

,CLAIMS.CLAIM_ZIPCODE

,CLAIMS.DIRECT_CASE_INC

,CLAIMS.OCC_CNT

,CLAIMS.DIRECT_CASE_INC*

(CASE WHEN CLAIMS.ACCIDENT_YEAR  IN(2013)

      THEN 1.00

  WHEN CLAIMS.LINE_GROUPING1='PERSONAL AUTO' AND CLAIMS.ACCIDENT_YEAR < 2013

      THEN COALESCE(COALESCE(TREND.TREND,AUTO_AVG.AVG_TREND),1.00)

  WHEN CLAIMS.LINE_GROUPING1='HOMEOWNERS' AND CLAIMS.ACCIDENT_YEAR BETWEEN 2007 AND (2013-1)

      THEN COALESCE(COALESCE(TREND.TREND,HOME_AVG.AVG_TREND),1.00)

  WHEN CLAIMS.LINE_GROUPING1='HOMEOWNERS' AND CLAIMS.ACCIDENT_YEAR =2006

      THEN COALESCE(COALESCE(TREND_HOME_2007.TREND,HOME_AVG_2007.AVG_TREND),1.00)

  ELSE 1.00 END)

AS EXP_ADJ_CASE_INC



 FROM mva.CLAIMS_STORM_LOSSES_TEMP AS CLAIMS

   LEFT OUTER JOIN mva.CLAIMS_Exposures_Trending AS TREND

 ON CLAIMS.LINE_GROUPING1 = TREND.LINE_GROUPING1

  AND CLAIMS.ACCIDENT_YEAR = TREND.ACCIDENT_YEAR

 AND CLAIMS.POLICY_STATE = TREND.STATE

AND CLAIMS.CLAIM_ZIPCODE = TREND.ZIPCODE

LEFT OUTER JOIN mva.CLAIMS_Exposures_Trending AS TREND_HOME_2007 #DONT HAVE A 2006 TREND FACTOR

ON CLAIMS.LINE_GROUPING1 = TREND_HOME_2007.LINE_GROUPING1

AND TREND_HOME_2007.ACCIDENT_YEAR=2007

AND CLAIMS.POLICY_STATE = TREND_HOME_2007.STATE

AND CLAIMS.CLAIM_ZIPCODE = TREND_HOME_2007.ZIPCODE  

LEFT OUTER JOIN mva.CLAIMS_Exposures_Auto_AVG_TREND AS AUTO_AVG

ON AUTO_AVG.ACCIDENT_YEAR = CLAIMS.ACCIDENT_YEAR

AND AUTO_AVG.STATE = CLAIMS.POLICY_STATE

LEFT OUTER JOIN mva.CLAIMS_Exposures_Home_AVG_TREND AS HOME_AVG

ON HOME_AVG.STATE = CLAIMS.POLICY_STATE

AND HOME_AVG.ACCIDENT_YEAR = CLAIMS.ACCIDENT_YEAR

LEFT OUTER JOIN mva.CLAIMS_Exposures_Home_AVG_TREND AS HOME_AVG_2007 #DONT HAVE A 2006   TREND FACTOR

ON HOME_AVG_2007.STATE = CLAIMS.POLICY_STATE

AND HOME_AVG_2007.ACCIDENT_YEAR = CLAIMS.ACCIDENT_YEAR

AND HOME_AVG_2007.ACCIDENT_YEAR=2007;

1 个答案:

答案 0 :(得分:0)

  1. 使用InnoDB数据库引擎
  2. 使用Explain查询检查是否使用了索引。适当的索引可以大大加快查询速度,因此它不会长时间锁定。