Query operations of hsqldb source code analysis series query Engines

Source: Internet
Author: User

The query process is parsed like insert. The final call is the getSingleResult method of the QuerySpecification class below. RangeVariable is the [java] private Result getSingleResult (Session session, int maxRows) related to the query conditions) {int [] limits = sortAndSlice. getLimits (session, this, maxRows); Result r = buildResult (session, limits); RowSetNavigatorData navigator = (RowSetNavigatorData) r. getNavigator (); if (isDistinctSelect) {navigator. removeDuplicates (session);} if (so RtAndSlice. hasOrder () {navigator. sortOrder (session);} if (limits! = SortAndSlice. defaultLimits &&! SortAndSlice. skipFullResult) {navigator. trim (limits [0], limits [1]);} return r;} private Result buildResult (Session session, int [] limits) {RowSetNavigatorData navigator = new RowSetNavigatorData (session, (QuerySpecification) this); Result result = Result. newResult (navigator); result. metaData = resultMetaData; if (isUpdatable) {result. rsProperties = ResultProperties. updatablePropsValue;} int s KipCount = 0; int limitCount = limits [2]; if (sortAndSlice. skipFullResult) {skipCount = limits [0]; limitCount = limits [1];} if (this. isSimpleCount) {Object [] data = new Object [indexLimitData]; Table table = rangeVariables [0]. getTable (); table. materialise (session); PersistentStore = table. getRowStore (session); long count = store. elementCount (session); data [0] = data [indexStartAggregates] = ValuePool. getLong (count); navigator. add (data); return result;} int fullJoinIndex = 0; RangeIterator [] rangeIterators = new RangeIterator [rangeVariables. length]; for (int I = 0; I <rangeVariables. length; I ++) {rangeIterators [I] = rangeVariables [I]. getIterator (session);} session. sessionContext. rownum = 1; for (int currentIndex = 0;) {if (currentIndex <fullJoinIndex) {// finished current s Pan // or finished outer rows on right navigator boolean end = true; for (int I = fullJoinIndex + 1; I <rangeVariables. length; I ++) {if (rangeVariables [I]. isRightJoin) {fullJoinIndex = I; currentIndex = I; end = false; (RangeIteratorRight) rangeIterators [I]). setOnOuterRows (); break ;}} if (end) {break ;}} RangeIterator it = rangeIterators [currentIndex]; if (it. next () {if (currentIndex <RangeVariables. length-1) {currentIndex ++; continue ;}} else {it. reset (); currentIndex --; continue;} if (limitCount = 0) {break;} session. sessionData. startRowProcessing (); Object [] data = new Object [indexLimitData]; for (int I = 0; I <indexStartAggregates; I ++) {if (isAggregated & aggresponcheck [I]) {continue;} else {data [I] = exprColumns [I]. getValue (session) ;}}for (int I = indexL ImitVisible; I <indexLimitRowId; I ++) {if (I = indexLimitVisible) {data [I] = it. getRowidObject ();} else {data [I] = it. getCurrentRow () ;}} session. sessionContext. rownum ++; if (skipCount> 0) {skipCount --; continue;} Object [] groupData = null; if (isAggregated | isGrouped) {groupData = navigator. getGroupData (data); if (groupData! = Null) {data = groupData ;}}for (int I = indexStartAggregates; I <indexLimitExpressions; I ++) {data [I] = exprColumns [I]. updateAggregatingValue (session, data [I]);} if (groupData = null) {navigator. add (data);} else if (isAggregated) {navigator. update (groupData, data);} int rowCount = navigator. getSize (); if (rowCount = session. resultMaxMemoryRows &&! IsAggregated &&! IsSingleMemoryTable) {navigator = new RowSetNavigatorDataTable (session, this, navigator); result. setNavigator (navigator);} if (isAggregated | isGrouped) {if (! SortAndSlice. isGenerated) {continue ;}}if (rowCount >= limitCount) {break ;}} navigator. reset (); for (int I = 0; I <rangeVariables. length; I ++) {rangeIterators [I]. reset ();} if (! IsGrouped &&! IsAggregated) {return result;} if (isAggregated) {if (! IsGrouped & navigator. getSize () = 0) {Object [] data = new Object [exprColumns. length]; for (int I = 0; I <indexStartAggregates; I ++) {if (! Aggresponcheck [I]) {data [I] = exprColumns [I]. getValue (session) ;}} navigator. add (data);} navigator. reset (); session. sessionContext. setRangeIterator (navigator); while (navigator. next () {Object [] data = navigator. getCurrent (); for (int I = indexStartAggregates; I <indexLimitExpressions; I ++) {data [I] = exprColumns [I]. getAggregatedValue (session, data [I]) ;}for (int I = 0; I <indexStartAggrega Tes; I ++) {if (aggresponcheck [I]) {data [I] = exprColumns [I]. getValue (session) ;}} session. sessionContext. unsetRangeIterator (navigator);} navigator. reset (); if (havingCondition! = Null) {while (navigator. hasNext () {Object [] data = (Object []) navigator. getNext (); if (! Boolean. TRUE. equals (data [indexLimitVisible + groupByColumnCount]) {navigator. remove () ;}} navigator. reset ();} return result;} For example, for a like operation, the query result is: This StatementQuery is really complicated, so you can understand it later.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.