| 32 | } |
| 33 | |
| 34 | @Override |
| 35 | protected final Expr opt(final CompileContext cc) throws QueryException { |
| 36 | compileData(cc); |
| 37 | arg(1, arg -> arg.simplifyFor(Simplify.DATA, cc).simplifyFor(Simplify.DISTINCT, cc)); |
| 38 | |
| 39 | // count number of results |
| 40 | final Data data = data(); |
| 41 | final IndexType type = type(); |
| 42 | if(type != IndexType.TOKEN && data != null && arg(1) instanceof Value) { |
| 43 | type.check(data, info); |
| 44 | long size = 0; |
| 45 | for(final byte[] token : tokens(cc.qc)) { |
| 46 | final int tl = token.length; |
| 47 | if(tl == 0 || tl > data.meta.maxlen) return this; |
| 48 | size += data.costs(new StringToken(type, token)).results(); |
| 49 | } |
| 50 | exprType.assign(seqType(), size); |
| 51 | } |
| 52 | return this; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public final boolean ddo() { |