ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/table/Plan.java

Path
ttomcat-1778514358873.zip-extract/_dependencies/maven/com.h2database_h2-2.2.220/org/h2/table/Plan.java
Status
scanned
Type
file
Name
Plan.java
Extension
.java
Programming language
Java
Mime type
text/x-java
File type
Java source, ASCII text
Tag

      
    
Rootfs path

      
    
Size
4922 (4.8 KB)
MD5
6fb0796a069c69ff5dec1fefa7ecb7be
SHA1
03f51bf307eb8c7f4808ee9385f52034ec766071
SHA256
7400703cf21ba922b7a3d1e288394274103f8b1d4dac6ce69a29a0f89007997e
SHA512

      
    
SHA1_git
ac6d7045696a4ce00ac92cc6cc17a9a4e4754731
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
Plan.java | 4.8 KB |

/* * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (https://h2database.com/html/license.html). * Initial Developer: H2 Group */ package org.h2.table; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import org.h2.command.query.AllColumnsForPlan; import org.h2.engine.SessionLocal; import org.h2.expression.Expression; import org.h2.expression.ExpressionVisitor; import org.h2.message.Trace; /** * A possible query execution plan. The time required to execute a query depends * on the order the tables are accessed. */ public class Plan { private final TableFilter[] filters; private final HashMap<TableFilter, PlanItem> planItems = new HashMap<>(); private final Expression[] allConditions; private final TableFilter[] allFilters; /** * Create a query plan with the given order. * * @param filters the tables of the query * @param count the number of table items * @param condition the condition in the WHERE clause */ public Plan(TableFilter[] filters, int count, Expression condition) { this.filters = new TableFilter[count]; System.arraycopy(filters, 0, this.filters, 0, count); final ArrayList<Expression> allCond = new ArrayList<>(); final ArrayList<TableFilter> all = new ArrayList<>(); if (condition != null) { allCond.add(condition); } for (int i = 0; i < count; i++) { TableFilter f = filters[i]; f.visit(f1 -> { all.add(f1); if (f1.getJoinCondition() != null) { allCond.add(f1.getJoinCondition()); } }); } allConditions = allCond.toArray(new Expression[0]); allFilters = all.toArray(new TableFilter[0]); } /** * Get the plan item for the given table. * * @param filter the table * @return the plan item */ public PlanItem getItem(TableFilter filter) { return planItems.get(filter); } /** * The the list of tables. * * @return the list of tables */ public TableFilter[] getFilters() { return filters; } /** * Remove all index conditions that can not be used. */ public void removeUnusableIndexConditions() { for (int i = 0; i < allFilters.length; i++) { TableFilter f = allFilters[i]; setEvaluatable(f, true); if (i < allFilters.length - 1) { // the last table doesn't need the optimization, // otherwise the expression is calculated twice unnecessarily // (not that bad but not optimal) f.optimizeFullCondition(); } f.removeUnusableIndexConditions(); } for (TableFilter f : allFilters) { setEvaluatable(f, false); } } /** * Calculate the cost of this query plan. * * @param session the session * @param allColumnsSet calculates all columns on-demand * @return the cost */ public double calculateCost(SessionLocal session, AllColumnsForPlan allColumnsSet) { Trace t = session.getTrace(); if (t.isDebugEnabled()) { t.debug("Plan : calculate cost for plan {0}", Arrays.toString(allFilters)); } double cost = 1; boolean invalidPlan = false; for (int i = 0; i < allFilters.length; i++) { TableFilter tableFilter = allFilters[i]; if (t.isDebugEnabled()) { t.debug("Plan : for table filter {0}", tableFilter); } PlanItem item = tableFilter.getBestPlanItem(session, allFilters, i, allColumnsSet); planItems.put(tableFilter, item); if (t.isDebugEnabled()) { t.debug("Plan : best plan item cost {0} index {1}", item.cost, item.getIndex().getPlanSQL()); } cost += cost * item.cost; setEvaluatable(tableFilter, true); Expression on = tableFilter.getJoinCondition(); if (on != null) { if (!on.isEverything(ExpressionVisitor.EVALUATABLE_VISITOR)) { invalidPlan = true; break; } } } if (invalidPlan) { cost = Double.POSITIVE_INFINITY; } if (t.isDebugEnabled()) { session.getTrace().debug("Plan : plan cost {0}", cost); } for (TableFilter f : allFilters) { setEvaluatable(f, false); } return cost; } private void setEvaluatable(TableFilter filter, boolean b) { filter.setEvaluatable(filter, b); for (Expression e : allConditions) { e.setEvaluatable(filter, b); } } }
Detected license expression
mpl-2.0 AND epl-1.0
Detected license expression (SPDX)
MPL-2.0 AND EPL-1.0
Percentage of license text
1.86
Copyrights
- end_line: 2
  copyright: Copyright 2004-2023 H2 Group. Multiple-Licensed
  start_line: 2
Holders
- holder: H2 Group. Multiple-Licensed
  end_line: 2
  start_line: 2
Authors

      
    
License detections License expression License expression SPDX
mpl_2_0_and_epl_1_0-796bf8d7-f485-3520-923d-e6a4b1ecd2f3 mpl-2.0 AND epl-1.0 MPL-2.0 AND EPL-1.0
URL Start line End line
https://h2database.com/html/license.html 3 3
Package URL License Primary language
pkg:osgi/com.h2database.source@2.2.220