Hi Henrik,

> (class +Proj +Macropisobj)
> (rel id (+Key +Number))
> (rel nm (+Ref +String))
> (rel sDate (+Ref +String))
> (rel eDate (+Ref +String))
> 
> (dm getCurrent> (Sdate Edate)
>    (filter '((P) (or
>                     (< Sdate (; P sDate) Edate)
>                     (< Sdate (; P eDate) Edate)
>                     (< Sdate (; P sDate) (; P eDate) Edate) ) )
>       (collect 'id This) ) )
> ...
> But how would the above problem be solved with Pilog and select if we have
> more than "a couple of hundred objects" in the database?

If you know that the *result* will be within a few hundred hits (not the
total DB size), and the difference between start and end is less than
e.g. 100 days, then you could first restrict the collection a bit

   (collect 'sDate '+Proj Sdate (+ Edate 100))

(works of course only for +Date types), and then filter that further.
This is surely the most efficient way for a small set of results.


The same you can do in Pilog with the 'db' predicate for an larger
result set, and if you want to avoid a 'select'

   (? @Rng (cons Sdate (+ Edate 100))
      (db sDate +Proj @Rng @Proj) )


But 'select' is the most general - and on big data sets perhaps the most
efficient - way. You could try

   (?
      @Sdate (cons Sdate T)      # Range with open end
      @Edate (cons Edate NIL)    # Reversed range with open start
      (select (@Proj)
         ((sDate +Proj @Sdate) (eDate +Proj @Edate))  # Search two indexes in 
parallel
         (range @Sdate @Proj sDate)                   # Check ranges
         (range @Edate @Proj eDate) ) )               # Check ranges

I haven't tested this ;)

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to