2017-12-12 136 views
-2

私はTableauでのデータを準備しています。現在、私は巨大なUNION ALLスクリプト(2つのテーブルのみを示す添付)を使って1つの大きなビューに結合する約12のテーブルを持っています。UNION ALLビューの実行が非常に遅い

Tableauでの私のパフォーマンスは非常に遅く、データをより効率的に構築する方法があることは確かです。現在、私は15分ごとにタブロー抽出をリフレッシュしなければならないので、データは真に「生きている」わけではありません。

助けてください。 おかげであなたが提供するもので

DROP VIEW XXXXX_alerts; 
CREATE 
    ALGORITHM = UNDEFINED 
    DEFINER = [email protected]% 
    SQL SECURITY DEFINER 
VIEW XXXXX_alerts AS 
    SELECT 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.ID AS ID, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.inspector AS Inspector, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.CREATED_DATE AS Created_Date, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.CREATED_LOCATION AS Created_Location, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.MODIFIED_DATE AS Modified_Date, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.MODIFIED_LOCATION AS Modified_Location, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.date1 AS date1, 
     NULL AS test_date_8200B, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.division AS division, 
     '8900' AS Form, 
     NULL AS Device_Type, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.coating_condition AS coating_condition, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.next_calibration_date AS next_calibration_date, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.pipe_barcode AS pipe_barcode, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.nitrogen_pressure_when_left_psig AS nitrogen_pressure_when_left_psig, 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form.is_nitrogen_left_value_correct AS is_nitrogen_left_value_correct, 
     NULL AS Location, 
     NULL AS Location_Conditional_Value, 
     NULL AS Town, 
     NULL AS readily_detectable_reading, 
     NULL AS threshold_level_gas, 
     NULL AS hefpa_shutoff, 
     NULL AS customers_signature, 
     NULL AS street, 
     NULL AS serial_number, 
     NULL AS tubing_filter_replaced_date, 
     NULL AS calibration_date, 
     NULL AS holiday_equipment_type, 
     NULL AS date_tag_issued, 
     NULL AS class, 
     NULL AS condition1, 
     NULL AS action_taken, 
     NULL AS reinspect_complete, 
     NULL AS person_designation, 
     NULL AS apartment_complex, 
     NULL AS result_of_contact_1, 
     NULL AS result_of_contact_2, 
     NULL AS date_letter_sent, 
     NULL AS date_clerk_sent_letter_to_customer_advocate, 
     NULL AS excessive_co_reinspect, 
     NULL AS tag_cleared, 
     NULL AS condition, 
     NULL AS date_of_contact_to_customer_service_for_locked_off_meter, 
     NULL AS date_tag_cleared, 
     NULL AS type_of_fitting, 
     NULL AS re_inspected_by_company_employee, 
     NULL AS inspection_Result, 
     NULL AS wo_sap_number, 
     NULL AS material_studied, 
     NULL AS time_studied, 
     NULL AS program, 
     NULL AS cgi_or_fi, 
     NULL AS component_picture, 
     NULL AS Test_Pressure, 
     NULL AS Test_Duration, 
     NULL AS Pipe_Footage, 
     NULL AS Pipe_Size, 
     NULL AS Barcode, 
     NULL AS Material 
    FROM 
     _data435329_XXXXX_12_pre_tested_pipe_inspection_form 
    UNION ALL SELECT 
     _data435329_XXXXX_10_2_quantitative_odorant.ID AS ID, 
     _data435329_XXXXX_10_2_quantitative_odorant.inspector AS Inspector, 
     _data435329_XXXXX_10_2_quantitative_odorant.CREATED_DATE AS Created_Date, 
     _data435329_XXXXX_10_2_quantitative_odorant.CREATED_LOCATION AS Created_Location, 
     _data435329_XXXXX_10_2_quantitative_odorant.MODIFIED_DATE AS Modified_Date, 
     _data435329_XXXXX_10_2_quantitative_odorant.MODIFIED_LOCATION AS Modified_Location, 
     NULL AS date1, 
     _data435329_XXXXX_10_2_quantitative_odorant.date1 AS test_date_8200B, 
     _data435329_XXXXX_10_2_quantitative_odorant.division AS division, 
     '8200B' AS Form, 
     NULL AS Device_Type, 
     NULL AS coating_condition, 
     NULL AS next_calibration_date, 
     NULL AS pipe_barcode, 
     NULL AS nitrogen_pressure_when_left_psig, 
     NULL AS is_nitrogen_left_value_correct, 
     _data435329_XXXXX_10_2_quantitative_odorant.location1 AS Location, 
     zcoptions.CONDITION_VALUE AS Location_Conditional_Value, 
     _data435329_XXXXX_10_2_quantitative_odorant.town AS Town, 
     _data435329_XXXXX_10_2_quantitative_odorant.odorometer_read_quantitative_readily_detectable___ AS readily_detectable_reading, 
     _data435329_XXXXX_10_2_quantitative_odorant.odorometer_read_quantitative_threshold_level___gas AS threshold_level_gas, 
     NULL AS hefpa_shutoff, 
     NULL AS customers_signature, 
     NULL AS street, 
     NULL AS serial_number, 
     NULL AS tubing_filter_replaced_date, 
     NULL AS calibration_date, 
     NULL AS holiday_equipment_type, 
     NULL AS date_tag_issued, 
     NULL AS class, 
     NULL AS condition1, 
     NULL AS action_taken, 
     NULL AS reinspect_complete, 
     NULL AS person_designation, 
     NULL AS apartment_complex, 
     NULL AS result_of_contact_1, 
     NULL AS result_of_contact_2, 
     NULL AS date_letter_sent, 
     NULL AS date_clerk_sent_letter_to_customer_advocate, 
     NULL AS excessive_co_reinspect, 
     NULL AS tag_cleared, 
     NULL AS condition, 
     NULL AS date_of_contact_to_customer_service_for_locked_off_meter, 
     NULL AS date_tag_cleared, 
     NULL AS type_of_fitting, 
     NULL AS re_inspected_by_company_employee, 
     NULL AS inspection_Result, 
     NULL AS wo_sap_number, 
     NULL AS material_studied, 
     NULL AS time_studied, 
     NULL AS program, 
     NULL AS cgi_or_fi, 
     NULL AS component_picture, 
     NULL AS Test_Pressure, 
     NULL AS Test_Duration, 
     NULL AS Pipe_Footage, 
     NULL AS Pipe_Size, 
     NULL AS Barcode, 
     NULL AS Material 
    FROM 
     (_data435329_XXXXX_10_2_quantitative_odorant 
     LEFT JOIN zcoptions ON ((zcoptions.KEY_VALUE = _data435329_XXXXX_10_2_quantitative_odorant.location1))) 
    WHERE 
     (zcoptions.OPTION_LIST_ID = 4553158) 
    GROUP BY _data435329_XXXXX_10_2_quantitative_odorant.ID 
    UNION ALL SELECT 
+1

「最初」を選ぶ:可能な回避策は、たとえば、最小を選択することです。あなたの照会は見るべき痛みです。 – Eric

+0

クエリでExplainプランを実行しましたか?これはTableauのパフォーマンスの問題のようには聞こえませんが、データベース側にあります。この複雑なUNION ALLテーブル12個は、自然にDBリソースを占有します。 Explainプランは、非効率な結合パスと索引付けが役立つ可能性のある場所を特定するのに役立ちます。 –

+0

データベースから取得したレコードの数はいくつですか? – Siva

答えて

2

、我々は唯一の

FROM (_data435329_XXXXX_10_2_quantitative_odorant 
    LEFT JOIN zcoptions 
      ON ((zcoptions.KEY_VALUE = 
       _data435329_XXXXX_10_2_quantitative_odorant.location1)) 
     ) 
    WHERE (zcoptions.OPTION_LIST_ID = 4553158) 
    GROUP BY _data435329_XXXXX_10_2_quantitative_odorant.ID 

WHERE (WHERE (zcoptions.OPTION_LIST_ID = 4553158) = 4553158)が効果的JOINLEFT JOINをオンに対処することができます。だから、なぜあなたはJOINと言っていないのだろうか?

インデックス:

zcoptions: INDEX(OPTION_LIST_ID) 

か、それは "カバー" にする、それ故に多少速く:

zcoptions: INDEX(OPTION_LIST_ID, KEY_VALUE, CONDITION_VALUE) 

これはEAVスキーマのようなにおい。その場合は、PRIMARY KEYなどを設定するには、hereのアドバイスに従ってください。その他のキー値表の場合も同様です。

匂い次のものがこのパターンです:

FROM a JOIN b ... 
GROUP BY a.id 

は私がJOINは、最初の行の数を乗算しているため、「 - 破を爆発」と呼んで、そしてGROUP BYはバックの行ごとに1つの行にそれをもたらしますテーブルの1つ。

JOINには、それぞれにbの複数の行があり、aには、GROUP BYが不要です。 (データを知らなくても、私はこれを予測することはできません。)この場合、クエリを表現する別の方法は

SELECT 
    ..., 
    (SELECT CONDITION_VALUE 
     FROM zcoptions 
     WHERE KEY_VALUE = _data435329_XXXXX_10_2_quantitative_odorant.location1 
      AND OPTION_LIST_ID = 4553158 
    ) AS Location_Conditional_Value, 
    ... 

で、JOINGROUP BYを取り除きます。

zcoptionsに複数の行がある場合、GROUP BYが不適切に形成されています。クエリは、グループ化されていない列を自由に混在させることができます。あなたのテーブルのエイリアスを作成してください

(SELECT min(CONDITION_VALUE) ... 

または

(SELECT CONDITION_VALUE ... LIMIT 1) as ...,