[ https://issues.apache.org/jira/browse/PHOENIX-1580?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14394019#comment-14394019 ]
James Taylor edited comment on PHOENIX-1580 at 4/3/15 3:36 AM: --------------------------------------------------------------- Always good when you construct any kind of collection to ask yourself "Do I know the size I expect it to be?". If the answer is yes, then instead of sizing it with the default size (as is currently being done), instantiate it later in the constructor where you have a better idea what the size might be. Also, no need for a scanSize member variable. Just return scans.size() {code} +public class UnionResultIterators implements ResultIterators { + private final List<KeyRange> splits; + private final List<List<Scan>> scans; + private final List<PeekingResultIterator>; + private final List<QueryPlan> plans; + + public UnionResultIterators(List<QueryPlan> plans) throws SQLException { + this.plans = plans; + int size = 0; + int nPlans = plans.size(); + iterators = Lists.newArrayListWithExpectedSize(nPlans); + splits = Lists.newArrayListWithExpectedSize(nPlans * 30); // Depends how many guideposts we're traversing + scans = Lists.newArrayListWithExpectedSize(nPlans * 10); // Depends how many regions we're traversing + for (QueryPlan plan : this.plans) { + iterators.add(LookAheadResultIterator.wrap(plan.iterator())); + splits.addAll(plan.getSplits()); // These shouldn't return null after calling plan.iterator() + scans.addAll(plan.getScans()); // The size() is scans.size(), so no need for additional scanSize member variable + } + } {code} was (Author: jamestaylor): Always good when you construct any kind of collection to ask yourself "Do I know the size I expect it to be?". If the answer is yes, then instead of sizing it with the default size (as is currently being done), instantiate it later in the constructor where you have a better idea what the size might be. Also, no need for a scanSize member variable. Just return scans.size() {code} +public class UnionResultIterators implements ResultIterators { + private final List<KeyRange> splits; + private final List<List<Scan>> scans; + private final List<PeekingResultIterator>; + private final List<QueryPlan> plans; + private final int scanSize; + + public UnionResultIterators(List<QueryPlan> plans) throws SQLException { + this.plans = plans; + int size = 0; + int nPlans = plans.size(); + iterators = Lists.newArrayListWithExpectedSize(nPlans); + splits = Lists.newArrayListWithExpectedSize(nPlans * 30); // Depends how many guideposts we're traversing + scans = Lists.newArrayListWithExpectedSize(nPlans * 10); // Depends how many regions we're traversing + for (QueryPlan plan : this.plans) { + iterators.add(LookAheadResultIterator.wrap(plan.iterator())); + splits.addAll(plan.getSplits()); // These shouldn't return null after calling plan.iterator() + scans.addAll(plan.getScans()); // The size() is scans.size(), so no need for additional scanSize member variable + } + } {code} > Support UNION ALL > ----------------- > > Key: PHOENIX-1580 > URL: https://issues.apache.org/jira/browse/PHOENIX-1580 > Project: Phoenix > Issue Type: Bug > Reporter: Alicia Ying Shu > Assignee: Alicia Ying Shu > Attachments: PHOENIX-1580-grammar.patch, Phoenix-1580-v1.patch, > Phoenix-1580-v2.patch, Phoenix-1580-v3.patch, Phoenix-1580-v4.patch, > Phoenix-1580-v5.patch, Phoenix-1580-v6.patch, Phoenix-1580-v7.patch, > phoenix-1580-v1-wipe.patch, phoenix-1580.patch, unionall-wipe.patch > > > Select * from T1 > UNION ALL > Select * from T2 -- This message was sent by Atlassian JIRA (v6.3.4#6332)