Project

General

Profile

« Previous | Next » 

Revision 2523

Added by sgarg about 19 years ago

Check if all the paths in returnfield are indexed. If yes, then you xml_path_index for getting values of returnfields instead of using xml_nodes + xml_index

View differences:

src/edu/ucsb/nceas/metacat/QuerySpecification.java
939 939
        MetaCatUtil.debugMessage("querySpecification.printExtendedSQL called\n", 35);
940 940
        StringBuffer self = new StringBuffer();
941 941

  
942
      // test if the are elements in the return fields
943
      if ( returnFieldList.size() == 0 ) {
944
          return null;
945
      }
946
      self.append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata, ");
947
      self.append("xml_nodes.parentnodeid ");
948
      self.append("from xml_index, xml_nodes where xml_index.nodeid=");
949
      self.append("xml_nodes.parentnodeid and (xml_index.path like '");
942
        boolean usePathIndex = true;
950 943

  
951
      boolean firstfield = true;
952
      //put the returnfields into the query
953
      //the for loop allows for multiple fields
954
      for (int i = 0; i < returnFieldList.size(); i++) {
955
          if (firstfield) {
956
              firstfield = false;
957
              self.append((String) returnFieldList.elementAt(i));
958
              self.append("' ");
959
          } else {
960
              self.append("or xml_index.path like '");
961
              self.append((String) returnFieldList.elementAt(i));
962
              self.append("' ");
963
          }
964
      }
965
      self.append(") AND xml_nodes.docid in (");
966
      self.append(doclist);
967
      self.append(") AND xml_nodes.nodetype = 'TEXT'");
944
        // test if the are elements in the return fields
945
        if ( returnFieldList.size() == 0 ) {
946
            return null;
947
        }
968 948

  
969
      addAccessRestrictionSQL(unaccessableNodePair, self);
949
        for (int i = 0; i < returnFieldList.size(); i++) {
950
            if(!MetaCatUtil.pathsForIndexing.contains
951
               (returnFieldList.elementAt(i))){
952
                usePathIndex = false;
953
                break;
954
            }
955
        }
970 956

  
971
      return self.toString();
957
        if(usePathIndex){
958
            self.append("select docid, path, nodedata, parentnodeid ");
959
            self.append("from xml_path_index where (path like '");
960

  
961
            boolean firstfield = true;
962
            //put the returnfields into the query
963
            //the for loop allows for multiple fields
964
            for (int i = 0; i < returnFieldList.size(); i++) {
965
                if (firstfield) {
966
                    firstfield = false;
967
                    self.append( (String) returnFieldList.elementAt(i));
968
                    self.append("' ");
969
                }
970
                else {
971
                    self.append("or path like '");
972
                    self.append( (String) returnFieldList.elementAt(i));
973
                    self.append("' ");
974
                }
975
            }
976
            self.append(") AND docid in (");
977
            self.append(doclist);
978
            self.append(")");
979

  
980
        } else {
981
            self.append("select xml_nodes.docid, xml_index.path, xml_nodes.nodedata,  ");
982
            self.append("xml_nodes.parentnodeid ");
983
            self.append("from xml_index, xml_nodes where xml_index.nodeid=");
984
            self.append("xml_nodes.parentnodeid and (xml_index.path like '");
985

  
986
            boolean firstfield = true;
987
            //put the returnfields into the query
988
            //the for loop allows for multiple fields
989
            for (int i = 0; i < returnFieldList.size(); i++) {
990
                if (firstfield) {
991
                    firstfield = false;
992
                    self.append((String) returnFieldList.elementAt(i));
993
                    self.append("' ");
994
                } else {
995
                    self.append("or xml_index.path like '");
996
                    self.append((String) returnFieldList.elementAt(i));
997
                    self.append("' ");
998
                }
999
            }
1000
            self.append(") AND xml_nodes.docid in (");
1001
            self.append(doclist);
1002
            self.append(") AND xml_nodes.nodetype = 'TEXT'");
1003

  
1004
        }
1005

  
1006
        addAccessRestrictionSQL(unaccessableNodePair, self);
1007

  
1008
        return self.toString();
972 1009
    }
973 1010

  
974 1011

  

Also available in: Unified diff