Skip to content

Commit c2f112c

Browse files
committed
Python: Filter _before_ the cartesian product
It's always a sad thing to see a good plan go wrong: 86860032 ~0% {4} r26 = JOIN r19 WITH DataFlowPublic::TupleElementContent#class#ff CARTESIAN PRODUCT OUTPUT Lhs.0 'nodeFrom', Lhs.1 'nodeTo', Rhs.0, Rhs.1 129256 ~3% {4} r27 = SELECT r26 ON In.3 <= 7 129256 ~0% {3} r28 = SCAN r27 OUTPUT In.0 'nodeFrom', In.2 'c', In.1 'nodeTo' Happily, now it looks like this: 129256 ~0% {3} r20 = JOIN r19 WITH DataFlowPrivate::small_tuple#f CARTESIAN PRODUCT OUTPUT Lhs.0 'nodeFrom', Rhs.0, Lhs.1 'nodeTo'
1 parent 8734df3 commit c2f112c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,10 +1517,13 @@ predicate forReadStep(CfgNode nodeFrom, Content c, Node nodeTo) {
15171517
or
15181518
c instanceof SetElementContent
15191519
or
1520-
c.(TupleElementContent).getIndex() <= 7
1520+
c = small_tuple()
15211521
)
15221522
}
15231523

1524+
pragma[noinline]
1525+
TupleElementContent small_tuple() { result.getIndex() <= 7 }
1526+
15241527
/**
15251528
* Holds if `nodeTo` is a read of an attribute (corresponding to `c`) of the object in `nodeFrom`.
15261529
*

0 commit comments

Comments
 (0)