1 21 22 package org.apache.derby.catalog.types; 23 24 import org.apache.derby.catalog.Statistics; 25 import org.apache.derby.iapi.services.io.Formatable; 26 import org.apache.derby.iapi.services.io.StoredFormatIds; 27 import org.apache.derby.iapi.services.io.FormatableHashtable; 28 import org.apache.derby.iapi.services.io.FormatableLongHolder; 29 30 import java.io.ObjectOutput ; 31 import java.io.ObjectInput ; 32 import java.io.IOException ; 33 34 public class StatisticsImpl implements Statistics, Formatable 35 { 36 41 42 private long numRows; 43 44 46 private long numUnique; 47 48 56 public StatisticsImpl(long numRows, long numUnique) 57 { 58 this.numRows = numRows; 59 this.numUnique = numUnique; 60 } 61 62 63 public StatisticsImpl() 64 {} 65 66 67 public double selectivity(Object [] predicates) 68 { 69 if (numRows == 0.0) 70 return 0.1; 71 72 75 return (double)(1/(double)numUnique); 76 } 77 78 79 80 83 public void readExternal(ObjectInput in) 84 throws IOException , ClassNotFoundException 85 { 86 FormatableHashtable fh = (FormatableHashtable)in.readObject(); 87 numRows = fh.getLong("numRows"); 88 numUnique = fh.getLong("numUnique"); 89 } 90 91 98 public void writeExternal(ObjectOutput out) 99 throws IOException 100 { 101 FormatableHashtable fh = new FormatableHashtable(); 102 fh.putLong("numRows", numRows); 103 fh.putLong("numUnique", numUnique); 104 out.writeObject(fh); 105 } 106 107 108 111 public int getTypeFormatId() 112 { 113 return StoredFormatIds.STATISTICS_IMPL_V01_ID; 114 } 115 116 117 118 public String toString() 119 { 120 return "numunique= " + numUnique + " numrows= " + numRows; 121 } 122 123 } 124 | Popular Tags |