time generation on linux vs windows
I think you are misusing `prefetch()`. In your first example, you shouldn't need prefetch at all if each X has only one (or zero) Y / Z. Just write:

```python
(X
 .select(X, Y, Z)
 .join_from(X, Y, JOIN.LEFT_OUTER)
 .join_from(X, Z, JOIN.LEFT_OUTER))
```

For your new version, since a Z can have many T's (if I'm reading this correctly), then yes you would probably be best off to use `prefetch()`. Again, though, you may be able to reuse the above snippet for the X, Y, and Z portions and just use prefetch for the T's.

I cannot really advise on how to optimize this, it depends so much on how many rows of X, Y, Z and T you are getting, what database you are using, etc, etc. It might be possible to use an aggregation to roll-up the related T's and skip using prefetch altogether.

Are you able to express the entire query in a single SQL SELECT (using plain old sql)? If yes, then we can probably optimize this. If no, then it will be hard to say.

I'll reopen this if there is a bug, but feel free to respond and I will do my best to help you.
Hey ,
I am using peewee 3.13.2
Part of the project include using join over multiple tables and retrieving foreign keys using prefetch.
I've recently added to the join new table that has many to many relationship and prefetch to retrieve it key.
**example:**

_old version:_
 X.select(X)
        .join_from(X, Y, peewee.JOIN.LEFT_OUTER)
        .join_from(X, Z, peewee.JOIN.LEFT_OUTER)
        .where(query)
        .prefetch(Y, Z)

_new version:_
 X.select(X)
        .join_from(X, Y, peewee.JOIN.LEFT_OUTER)
        .join_from(X, Z, peewee.JOIN.LEFT_OUTER)
        .join_from(Z, T, peewee.JOIN.LEFT_OUTER)
        .switch(X)
        .where(query)
        .prefetch(Y, Z,T)
**questions**
1. is there a better why (lower time complexity) to model this behavior without limiting the query that the user can give?
2. why do i get better time complexity in windows?
    * The same branch (and same test) get on windows: 340 sec and in linux:870 sec
    * Just for comparison before the change i've got windows:200 sec linux: 250 sec 