2016-10-24 3 views
1

次のような大きなSQL文があります。大規模な "共用体を選択する"構成 - 「多すぎる関係 - プロシージャー・ビュー」を取り除く方法。最大許容値は255です。

はできるだけ早くunion allと組み合わせる128個の以上のエントリがあるとして、私はこのエラーを取得する:Too many Contexts of Relation-Procedure-Views. Maximum allowed is 255

は、どのように私は、クエリがエラーを取り除くために再公式化することができますか?

このデータをデータベースに追加する方法はありません(データベースの健全性チェックを行うスクリプトにあり、読み取り専用モードにすることができるため、スクリプトには読み取り専用アクセス権があります)。下列の

  • ididentifier各行
  • idに異なる値を有していては数値IDであり、それは(
  • identifierは英数字の名前で事前に知られているギャップを有します下のクエリとは異なり、idからidentifierを生成できません)
  • usageには2つの文字列値があります。 idの特定のグループのために有効である(私は別のunion all構築物中にそれらを置くことができます)
  • commentは(ので、私は同様に別のunion all構築物中にそれらを置くことができidの特定のグループに対して有効である約20の異なる文字列値を持っています)

これを再現するクエリ:

-- 20161024 - Too many Contexts of Relation-Procedure-Views. Maximum allowed is 255 
with parameters as 
(
select 1001 as id 
    , '1001' as usage 
    , 'PP_1001' as identifier 
    , '1001' as comment 
from rdb$database 

union all select 1002,'1002','PP_1002','1002' from rdb$database 
union all select 1003,'1003','PP_1003','1003' from rdb$database 
union all select 1004,'1004','PP_1004','1004' from rdb$database 
union all select 1005,'1005','PP_1005','1005' from rdb$database 
union all select 1006,'1006','PP_1006','1006' from rdb$database 
union all select 1007,'1007','PP_1007','1007' from rdb$database 
union all select 1008,'1008','PP_1008','1008' from rdb$database 
union all select 1009,'1009','PP_1009','1009' from rdb$database 
union all select 1010,'1010','PP_1010','1010' from rdb$database 
union all select 1011,'1011','PP_1011','1011' from rdb$database 
union all select 1012,'1012','PP_1012','1012' from rdb$database 
union all select 1013,'1013','PP_1013','1013' from rdb$database 
union all select 1014,'1014','PP_1014','1014' from rdb$database 
union all select 1015,'1015','PP_1015','1015' from rdb$database 
union all select 1016,'1016','PP_1016','1016' from rdb$database 
union all select 1017,'1017','PP_1017','1017' from rdb$database 
union all select 1018,'1018','PP_1018','1018' from rdb$database 
union all select 1019,'1019','PP_1019','1019' from rdb$database 
union all select 1020,'1020','PP_1020','1020' from rdb$database 
union all select 1021,'1021','PP_1021','1021' from rdb$database 
union all select 1022,'1022','PP_1022','1022' from rdb$database 
union all select 1023,'1023','PP_1023','1023' from rdb$database 
union all select 1024,'1024','PP_1024','1024' from rdb$database 
union all select 1025,'1025','PP_1025','1025' from rdb$database 
union all select 1026,'1026','PP_1026','1026' from rdb$database 
union all select 1027,'1027','PP_1027','1027' from rdb$database 
union all select 1028,'1028','PP_1028','1028' from rdb$database 
union all select 1029,'1029','PP_1029','1029' from rdb$database 
union all select 1030,'1030','PP_1030','1030' from rdb$database 
union all select 1031,'1031','PP_1031','1031' from rdb$database 
union all select 1032,'1032','PP_1032','1032' from rdb$database 
union all select 1033,'1033','PP_1033','1033' from rdb$database 
union all select 1034,'1034','PP_1034','1034' from rdb$database 
union all select 1035,'1035','PP_1035','1035' from rdb$database 
union all select 1036,'1036','PP_1036','1036' from rdb$database 
union all select 1037,'1037','PP_1037','1037' from rdb$database 
union all select 1038,'1038','PP_1038','1038' from rdb$database 
union all select 1039,'1039','PP_1039','1039' from rdb$database 
union all select 1040,'1040','PP_1040','1040' from rdb$database 
union all select 1041,'1041','PP_1041','1041' from rdb$database 
union all select 1042,'1042','PP_1042','1042' from rdb$database 
union all select 1043,'1043','PP_1043','1043' from rdb$database 
union all select 1044,'1044','PP_1044','1044' from rdb$database 
union all select 1045,'1045','PP_1045','1045' from rdb$database 
union all select 1046,'1046','PP_1046','1046' from rdb$database 
union all select 1047,'1047','PP_1047','1047' from rdb$database 
union all select 1048,'1048','PP_1048','1048' from rdb$database 
union all select 1049,'1049','PP_1049','1049' from rdb$database 
union all select 1050,'1050','PP_1050','1050' from rdb$database 
union all select 1051,'1051','PP_1051','1051' from rdb$database 
union all select 1052,'1052','PP_1052','1052' from rdb$database 
union all select 1053,'1053','PP_1053','1053' from rdb$database 
union all select 1054,'1054','PP_1054','1054' from rdb$database 
union all select 1055,'1055','PP_1055','1055' from rdb$database 
union all select 1056,'1056','PP_1056','1056' from rdb$database 
union all select 1057,'1057','PP_1057','1057' from rdb$database 
union all select 1058,'1058','PP_1058','1058' from rdb$database 
union all select 1059,'1059','PP_1059','1059' from rdb$database 
union all select 1060,'1060','PP_1060','1060' from rdb$database 
union all select 1061,'1061','PP_1061','1061' from rdb$database 
union all select 1062,'1062','PP_1062','1062' from rdb$database 
union all select 1063,'1063','PP_1063','1063' from rdb$database 
union all select 1064,'1064','PP_1064','1064' from rdb$database 
union all select 1065,'1065','PP_1065','1065' from rdb$database 
union all select 1066,'1066','PP_1066','1066' from rdb$database 
union all select 1067,'1067','PP_1067','1067' from rdb$database 
union all select 1068,'1068','PP_1068','1068' from rdb$database 
union all select 1069,'1069','PP_1069','1069' from rdb$database 
union all select 1070,'1070','PP_1070','1070' from rdb$database 
union all select 1071,'1071','PP_1071','1071' from rdb$database 
union all select 1072,'1072','PP_1072','1072' from rdb$database 
union all select 1073,'1073','PP_1073','1073' from rdb$database 
union all select 1074,'1074','PP_1074','1074' from rdb$database 
union all select 1075,'1075','PP_1075','1075' from rdb$database 
union all select 1076,'1076','PP_1076','1076' from rdb$database 
union all select 1077,'1077','PP_1077','1077' from rdb$database 
union all select 1078,'1078','PP_1078','1078' from rdb$database 
union all select 1079,'1079','PP_1079','1079' from rdb$database 
union all select 1080,'1080','PP_1080','1080' from rdb$database 
union all select 1081,'1081','PP_1081','1081' from rdb$database 
union all select 1082,'1082','PP_1082','1082' from rdb$database 
union all select 1083,'1083','PP_1083','1083' from rdb$database 
union all select 1084,'1084','PP_1084','1084' from rdb$database 
union all select 1085,'1085','PP_1085','1085' from rdb$database 
union all select 1086,'1086','PP_1086','1086' from rdb$database 
union all select 1087,'1087','PP_1087','1087' from rdb$database 
union all select 1088,'1088','PP_1088','1088' from rdb$database 
union all select 1089,'1089','PP_1089','1089' from rdb$database 
union all select 1090,'1090','PP_1090','1090' from rdb$database 
union all select 1091,'1091','PP_1091','1091' from rdb$database 
union all select 1092,'1092','PP_1092','1092' from rdb$database 
union all select 1093,'1093','PP_1093','1093' from rdb$database 
union all select 1094,'1094','PP_1094','1094' from rdb$database 
union all select 1095,'1095','PP_1095','1095' from rdb$database 
union all select 1096,'1096','PP_1096','1096' from rdb$database 
union all select 1097,'1097','PP_1097','1097' from rdb$database 
union all select 1098,'1098','PP_1098','1098' from rdb$database 
union all select 1099,'1099','PP_1099','1099' from rdb$database 
union all select 1100,'1100','PP_1100','1100' from rdb$database 
union all select 1101,'1101','PP_1101','1101' from rdb$database 
union all select 1102,'1102','PP_1102','1102' from rdb$database 
union all select 1103,'1103','PP_1103','1103' from rdb$database 
union all select 1104,'1104','PP_1104','1104' from rdb$database 
union all select 1105,'1105','PP_1105','1105' from rdb$database 
union all select 1106,'1106','PP_1106','1106' from rdb$database 
union all select 1107,'1107','PP_1107','1107' from rdb$database 
union all select 1108,'1108','PP_1108','1108' from rdb$database 
union all select 1109,'1109','PP_1109','1109' from rdb$database 
union all select 1110,'1110','PP_1110','1110' from rdb$database 
union all select 1111,'1111','PP_1111','1111' from rdb$database 
union all select 1112,'1112','PP_1112','1112' from rdb$database 
union all select 1113,'1113','PP_1113','1113' from rdb$database 
union all select 1114,'1114','PP_1114','1114' from rdb$database 
union all select 1115,'1115','PP_1115','1115' from rdb$database 
union all select 1116,'1116','PP_1116','1116' from rdb$database 
union all select 1117,'1117','PP_1117','1117' from rdb$database 
union all select 1118,'1118','PP_1118','1118' from rdb$database 
union all select 1119,'1119','PP_1119','1119' from rdb$database 
union all select 1120,'1120','PP_1120','1120' from rdb$database 
union all select 1121,'1121','PP_1121','1121' from rdb$database 
union all select 1122,'1122','PP_1122','1122' from rdb$database 
union all select 1123,'1123','PP_1123','1123' from rdb$database 
union all select 1124,'1124','PP_1124','1124' from rdb$database 
union all select 1125,'1125','PP_1125','1125' from rdb$database 
union all select 1126,'1126','PP_1126','1126' from rdb$database 
union all select 1127,'1127','PP_1127','1127' from rdb$database 
union all select 1128,'1128','PP_1128','1128' from rdb$database 
--union all select 1129,'1129','PP_1129','1129' from rdb$database 
) 
select parameters.id 
    , parameters.usage 
    , parameters.identifier 
    , parameters.comment 
from parameters 
where parameters.id <> -1 
order by parameters.id 
+0

つの質問:あなたは一時テーブルを作成できますか?はいの場合は、カーソルで試してみましたので、一時テーブルにデータを入力してから、最後にunionを選択せず​​に適用できますか? –

+1

あなたはいつも連続しているのですか?(他の値についても同じ質問です)もしそうなら、再帰的な値を使って懐疑表を作成してテンポラリテーブル – Nemeros

+0

を作成することができます(このコメントで質問が更新されます)。@JoeTarasスクリプトはDBを潜在的に読み取り専用とみなさなければなりません。 –

答えて

0

Aは、以下のいずれかが、私は行くを取得する必要がありますように構築します。

paramsは、粗く塗りつぶされた人工のparametersテーブルと比較する必要があるデータベース内のテーブルです。使用

テクニック:whencaseが存在するであろう実際のクエリの列

を充填するIDs

  • case構築物におけるID値のシーケンスを生成する

    • 再帰クエリすべてのvalidId値についてはthenであり、小文字の場合にはcase構造体より少ない値を必要とするns。エラーなし

      問合せ:

      select parameters.id 
          , parameters.usage 
          , parameters.identifier 
          , parameters.comment 
          , params.ID param_id 
          , params.AVALUE 
          , params.DESCRIPTION 
      from 
      (
          with recursive IDs as 
          (
          select 0 as ID from rdb$database 
          union all 
          select 1 + ID from IDs where ID < 1000 
      ) 
      select 
          ID  
          , case 
           when ((ID = 999) or (ID between 0 and 130)) 
           then 1 
           else 0 
          end as validId 
          , case 
           when ID in 
           ( 
               3, 
              12, 13, 14, 15, 16, 17, 18, 19, 
           20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 
           30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 
             41, 42,     46, 47, 
           50, 51, 52,  54, 55, 56, 57, 58, 59, 
           60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 
           70, 71, 72,         79, 
           80,    83, 84, 85, 86, 87, 88, 89, 
           90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 
           100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 
           110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 
           120, 121, 122, 123, 124, 125, 126, 127,  129, 
           999 
          ) 
           then 'used' 
           else 'unused' 
          end as usage 
          , '' as identifier 
          , '' as comment 
      from 
          IDs 
      ) parameters    
      full outer join params 
          on params.ID = parameters.id 
      where parameters.validId = 1 
      order by params.id, parameters.id 
      
  • 関連する問題