0

私のクエリはこれまでに 30 分間実行されています。

SELECT 
   d.accn_id,
   cast(d.load_date as DATE) as LoadDate,
   cast (d.final_rpt_date as DATE) as FinalReportDate,
   sum(p.paid_amt) as SumPaidAmt,
   payors.PAYOR_ID
FROM accn_demographics d
    JOIN accn_payments p
        ON d.ACCN_ID=p.ACCN_ID    
    JOIN accn_payors payors
        ON payors.X_PAYOR_ID=p.X_PAYMENT_PAYOR_ID
WHERE
      p.POSTED = 'y'
  AND p.PMT_DATE between '20120401' and '20120430'    
GROUP BY
    d.accn_id,
    d.load_date,
    d.final_rpt_date,
    payors.PAYOR_ID

このテーブルを追加する前に:

accn_payors

クエリには数分かかりましたが、このテーブルを追加した後、30 分後も待機しています。

ここに3つのテーブルがあります:

USE [zzzDataEOMTestingApril]
GO

/****** Object:  Table [dbo].[accn_payors]    Script Date: 08/20/2012 13:28:20 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[accn_payors](
    [ACCN_ID] [varchar](40) NULL,
    [PAYOR_PRIORITY] [int] NULL,
    [PAYOR_ID] [varchar](15) NULL,
    [PAYOR_NAME] [varchar](40) NULL,
    [GROUP_ID] [varchar](40) NULL,
    [PLAN_ID] [varchar](40) NULL,
    [SUBSCRIBER_ID] [varchar](40) NULL,
    [INSURED_RELATIONSHIP] [varchar](6) NULL,
    [INSURED_L_NAME] [varchar](40) NULL,
    [INSURED_F_NAME] [varchar](40) NULL,
    [INSURED_HOME_PHN] [varchar](40) NULL,
    [INSURED_WORK_PHN] [varchar](40) NULL,
    [INSURED_ADDR1] [varchar](60) NULL,
    [INSURED_ADDR2] [varchar](60) NULL,
    [INSURED_CITY] [varchar](60) NULL,
    [INSURED_STATE] [varchar](2) NULL,
    [INSURED_ZIPCODE] [varchar](10) NULL,
    [PAID_IN_FULL] [varchar](1) NULL,
    [CLAIM_COMMENT] [varchar](4000) NULL,
    [OTHER_INFO1] [varchar](4000) NULL,
    [OTHER_INFO2] [varchar](4000) NULL,
    [OTHER_INFO3] [varchar](4000) NULL,
    [OTHER_INFO4] [varchar](4000) NULL,
    [INTERNAL_NOTES] [varchar](4000) NULL,
    [SYSTEM_ADDED_PAYOR] [varchar](1) NULL,
    [ELIG_OK] [varchar](1) NULL,
    [ELIG_STATUS] [varchar](40) NULL,
    [ELIG_SERVICE] [varchar](40) NULL,
    [ELIG_VERIF_ID] [varchar](15) NULL,
    [AUD_REC_ID] [int] NOT NULL,
    [INSURED_DOB] [varchar](50) NULL,
    [INSURED_SEX] [varchar](3) NULL,
    [EMPLOYER_NAME] [varchar](40) NULL,
    [EMPLOYER_ADDR1] [varchar](60) NULL,
    [EMPLOYER_ADDR2] [varchar](60) NULL,
    [EMPLOYER_CITY] [varchar](60) NULL,
    [EMPLOYER_STATE] [varchar](2) NULL,
    [EMPLOYER_ZIPCODE] [varchar](10) NULL,
    [EMPLOYER_COUNTRY] [varchar](40) NULL,
    [EMPLOYER_PHONE] [varchar](40) NULL,
    [EMPLOYMENT_STATUS] [varchar](40) NULL,
    [GROUP_NAME] [varchar](40) NULL,
    [X_PAYOR_ID] [int] NULL,
    [AUDIT_DATE] [varchar](50) NULL,
    [OCCURRENCE_CODE] [varchar](30) NULL,
    [INSURED_SSN] [int] NULL,
    [OCCURRENCE_CODE_DATE] [datetime] NULL,
    [DELAY_REASON_CODE] [varchar](15) NULL,
    [CASE_ID] [varchar](60) NULL,
    [PAYOR_CODE_TYPE] [varchar](400) NULL,
    [AUTH_NUM] [varchar](40) NULL,
 CONSTRAINT [PK_accn_payors] PRIMARY KEY CLUSTERED 
(
    [AUD_REC_ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


USE [zzzDataEOMTestingApril]
GO

/****** Object:  Table [dbo].[accn_payments]    Script Date: 08/20/2012 13:28:35 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[accn_payments](
    [ACCN_ID] [varchar](40) NULL,
    [PMT_SEQUENCE] [int] NULL,
    [DEPOSIT_ID] [int] NULL,
    [DEPOSIT_BATCH_ID] [int] NULL,
    [DEPOSIT_BATCH_SEQ] [int] NULL,
    [PROC_CODE] [varchar](40) NULL,
    [PMT_TYPE] [varchar](40) NULL,
    [USER_ID] [varchar](20) NULL,
    [NOTE] [varchar](4000) NULL,
    [PMT_DATE] [datetime] NULL,
    [CHECK_NUM] [varchar](40) NULL,
    [RECEIPT_NUM] [varchar](40) NULL,
    [ALLOWED_AMT] [float] NULL,
    [DEDUCT_AMT] [float] NULL,
    [PAID_AMT] [float] NULL,
    [COPAY_AMT] [float] NULL,
    [POSTED] [varchar](1) NULL,
    [BULK] [varchar](1) NULL,
    [UNITS_PAID] [int] NULL,
    [BILL_AMT_FROM_EOB] [float] NULL,
    [PAYMENT_PAYOR_ID] [varchar](15) NULL,
    [PRICED_PAYOR_ID] [varchar](15) NULL,
    [AUD_REC_ID] [int] NULL,
    [X_ACCN_BILLED_PROCEDURE_ID] [int] NULL,
    [X_PRICED_PAYOR_ID] [int] NULL,
    [X_PAYMENT_PAYOR_ID] [int] NULL,
    [CLIENT_PRIMARY_FACILITY_ID] [varchar](15) NULL,
    [REMIT_FILE_NAME] [varchar](128) NULL,
    [BATCH_POSTED] [varchar](1) NULL,
    [DEPOSIT_POSTED] [varchar](1) NULL,
    [AUDIT_DATE] [datetime] NULL,
    [ACCEPT_ASSIGNMENT] [varchar](1) NULL,
    [EXPECT_PRICE_DISCREPENCY_AMT] [float] NULL,
    [PRINT_NOTE] [varchar](1) NULL,
    [PATIENT_RESP_AMT] [float] NULL,
    [EOB] [varchar](40) NULL,
    [ICN] [varchar](30) NULL,
    [DEPOSIT_NOTE] [varchar](40) NULL,
    [NETWORK_ID] [varchar](100) NULL,
    [USE_EXPECT_PRICE] [varchar](1) NULL,
    [CO_INS_AMT] [float] NULL,
    [REMIT_DATE] [datetime] NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


USE [zzzDataEOMTestingApril]
GO

/****** Object:  Table [dbo].[accn_demographics]    Script Date: 08/20/2012 13:28:48 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[accn_demographics](
    [ACCN_ID] [varchar](40) NULL,
    [STATUS] [varchar](15) NULL,
    [CLIENT_ID] [varchar](15) NULL,
    [CLIENT_NAME] [varchar](60) NULL,
    [REQ_ID] [varchar](20) NULL,
    [DOS] [datetime] NULL,
    [SEX] [varchar](3) NULL,
    [PT_ID] [varchar](40) NULL,
    [ORDERING UPIN] [bit] NULL,
    [PT_L_NAME] [varchar](40) NULL,
    [PT_F_NAME] [varchar](40) NULL,
    [PT_AGE] [varchar](40) NULL,
    [DOB] [date] NULL,
    [PT_HOME_PHM] [varchar](40) NULL,
    [PT_WORK_PHN] [varchar](40) NULL,
    [PT_ADDR1] [varchar](60) NULL,
    [PT_ADDR2] [varchar](60) NULL,
    [PT_ZIPCODE] [varchar](10) NULL,
    [PT_CITY] [varchar](60) NULL,
    [PT_ST_ID] [varchar](2) NULL,
    [PT_SSN] [int] NULL,
    [RECEIPT_DATE] [datetime] NULL,
    [INDIGENT_PCT] [float] NULL,
    [PRICE_DATE] [datetime] NULL,
    [EXPECT_PRICE] [float] NULL,
    [BILL_PRICE] [float] NULL,
    [GROSS_PRICE] [float] NULL,
    [DUE_AMT] [float] NULL,
    [ACCOUNTING_DATE] [datetime] NULL,
    [FINAL_RPT_DATE] [datetime] NULL,
    [TIME_OF_SERVICE] [varchar](20) NULL,
    [NO_CHARGE] [varchar](1) NULL,
    [AUD_REC_ID] [int] NULL,
    [ORIGINAL_ACCOUNTING_DATE] [datetime] NULL,
    [PT_COUNTRY] [varchar](40) NULL,
    [PHLEB_FACILITY] [varchar](40) NULL,
    [FASTING_TYPE] [varchar](40) NULL,
    [PT_LOCATION] [varchar](40) NULL,
    [PHLEB_USER_ID] [varchar](40) NULL,
    [PRIMARY_CLIENT_ID] [varchar](15) NULL,
    [PHYSICIAN_SOF] [varchar](1) NULL,
    [PATIENT_SOF] [varchar](1) NULL,
    [STAT] [varchar](1) NULL,
    [CALLBACK] [varchar](1) NULL,
    [PT_REPORT_COPY] [varchar](1) NULL,
    [PT_EMAIL] [varchar](40) NULL,
    [PAID_IN_FULL] [varchar](1) NULL,
    [CLIENT_STATEMENT_DATE] [datetime] NULL,
    [RETRO_BILL_PRICE] [float] NULL,
    [PATIENT_TYPE] [varchar](40) NULL,
    [REFERRING_UPIN] [bit] NULL,
    [PRIMARY_UPIN] [bit] NULL,
    [LOAD_DATE] [datetime] NULL,
    [TRIP_STOPS] [int] NULL,
    [TRIP_MILES] [int] NULL,
    [ROUND_TRIP] [varchar](1) NULL,
    [TRIP_PATIENT_COUNT] [int] NULL,
    [ADMISSION_SOURCE] [varchar](40) NULL,
    [EMERGENCY] [varchar](1) NULL,
    [ACCIDENT_CAUSE] [varchar](40) NULL,
    [PATIENT_MARITAL_STATUS] [varchar](40) NULL,
    [ADMISSION_TYPE] [varchar](40) NULL,
    [PATIENT_STATUS] [varchar](200) NULL,
    [WORPCOMP_CASE_WORKER] [varchar](80) NULL,
    [MRO] [varchar](40) NULL,
    [X_CLIENT_ID] [int] NULL,
    [X_PRIMARY_CLIENT_ID] [int] NULL,
    [AUDIT_DATE] [datetime] NULL,
    [ORDERING_NPI] [bit] NULL,
    [REFERRING_NPI] [bit] NULL,
    [PRIMARY_NPI] [bit] NULL,
    [CLIENT_PRODUCT] [int] NULL,
    [ONSET_DATE] [date] NULL,
    [ONSET_TYPE] [varchar](10) NULL,
    [ACCIDENT_STATE_ID] [varchar](2) NULL,
    [TRADE_DISCOUNT_AMOUNT] [float] NULL,
    [RETRO_TRADE_DISC_AMT] [float] NULL,
    [PATIENT_PREGNANT] [varchar](1) NULL,
    [PATIENT_GRAVIDA] [int] NULL,
    [ORDERING_PHYS_NAME] [varchar](80) NULL,
    [X_ORDERING_PHYS_ID] [int] NULL,
    [REFERRING_PHYS_NAME] [varchar](80) NULL,
    [X_ REFERRING_PHYS_ID] [int] NULL,
    [PRIMARY_PHYS_NAME] [varchar](80) NULL,
    [X_ PRIMARY _PHYS_ID] [int] NULL,
    [ADMISSION_DT] [date] NULL,
    [ADMISSION_TIME] [varchar](5) NULL,
    [DISCHARGE_DT] [date] NULL,
    [DISCHARGE_TIME] [varchar](5) NULL
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

質問どうすればこのクエリを高速化できますか? 不足しているインデックスはありますか? テーブルを 1 つだけ追加すると、このクエリの結果を返すのにかかる時間が指数関数的に増加するのはなぜですか? おそらく私はいくつかのデータ型を変更する必要がありますか?

4

5 に答える 5

3

支払人への参加は正しいですか? 支払人テーブルには、支払人 ID と同様に accnid があります。

結合条件を次のように変更してみてください。

join accn_payors payors
     on  payors.X_PAYOR_ID=p.X_PAYMENT_PAYOR_ID and
        payors.ACCN_ID = p.ACCN_ID

アカウントとは独立した支払人情報を含む別のテーブルはありますか?

于 2012-08-20T20:42:30.537 に答える
1

accn_payors.X_PAYOR_IDに追加accn_payors.PAYOR_IDしてインデックスを付け、そのインデックスの「含まれる列」に追加します。また、列にインデックスを追加しますaccn_payments.X_PAYMENT_PAYOR_ID

于 2012-08-20T20:34:01.133 に答える
1

以下を試してください

Select 
    sum(p.paid_amt) as SumPaidAmt,
    p.ACCN_ID,
    p.X_PAYMENT_PAYOR_ID,
    cast(d.load_date as DATE) as LoadDate,
    cast (d.final_rpt_date as DATE) as FinalReportDate,
From
(
    SELECT     
            p.paid_amt,
            p.ACCN_ID,
            p.X_PAYMENT_PAYOR_ID
    From    accn_payments p
    Where   p.POSTED = 'y'
    AND     p.PMT_DATE between '20120401' and '20120430'    
)p
INNER Join accn_demographics    d           ON d.ACCN_ID=p.ACCN_ID
JOIN accn_payors                payors      ON payors.X_PAYOR_ID=p.X_PAYMENT_PAYOR_ID
GROUP BY
    d.accn_id,
    d.load_date,
    d.final_rpt_date,
    payors.PAYOR_ID
于 2012-08-20T21:17:08.737 に答える
1

外部キーにインデックスを付けることは間違いなく役に立ちます。この場合、accn_payors.X_PAYOR_ID のインデックスが違いを生むはずです。

テーブル内のデータ量は?

于 2012-08-20T20:35:01.900 に答える
0

SQL Management Studio で計画されたクエリの実行を調べてみましたか? インデックスの欠落に関するヒントを提供する場合もあります。

于 2012-08-20T20:52:37.670 に答える