title: When I filtering a queryset according to created date Postgres is taking 100% cpu and it never ends
body: <p>I have come across a problem when working on a simple project. When I executed a query the Postgres is taking 100% CPU and it never stops (I had to kill the process 2 minutes after).</p>
  <p>These are my models related to this issue</p>
  <pre><code>class ProjectUser(AbstractBaseUser, PermissionsMixin):
      username = models.CharField('Username', blank=False, db_index=True, max_length=255, unique=True)
      email = models.EmailField('Email', blank=True, null=True, db_index=True, unique=True)
      first_name = models.CharField('First Name', max_length=128)
      last_name = models.CharField('Last Name', max_length=128, blank=True)
      nick_name = models.CharField('Stage Name', max_length=128, null=True, blank=True)
      is_staff = models.BooleanField('Staff Status', default=False,
                                     help_text='Designates whether the user can log into this admin site.',
                                     db_index=True)
      is_active = models.BooleanField('Active', default=True,
                                      help_text=('Designates whether this user should be treated as '
                                                 'active. Deselect this instead of deleting accounts.'), db_index=True)
                                           default=SIGN_UP_SOURCE_CHOICES.regular)
      gender = models.IntegerField('Gender', choices=[1, 2], default=1,
                                   db_index=True)
      phone = models.CharField('Phone Number', null=True, blank=True, max_length=15)
      created_date = models.DateTimeField('Created Date', auto_now_add=True)
      modified_date = models.DateTimeField('Modified Date', auto_now=True)
  
  
  
  
  class UserConnect(models.Model):
      from_user = models.ForeignKey('users.ProjectUser', related_name='connect_from_user', on_delete=models.CASCADE)
      to_user = models.ForeignKey('users.ProjectUser', related_name='connect_to_user', on_delete=models.CASCADE)
      created_date = models.DateTimeField('Created Date', auto_now_add=True)
  
  
  class ProjectRequest(models.Model):
      project_title = models.CharField('Project title', max_length=255, blank=True, null=True)
      project_from_user = models.ForeignKey('users.ProjectUser', related_name='request_user', on_delete=models.CASCADE)
      project_to_user = models.ForeignKey('users.ProjectUser', related_name='request_to_user', on_delete=models.CASCADE)
      project_details = models.TextField(name='project_details')
      request_status = models.IntegerField(choices=[0, 1, 2], default=0)
  </code></pre>
  <p>This is the query that I have used</p>
  <pre><code>query_set = ProjectUser.objects.prefetch_related('connect_from_user', 'request_user')
  if months:
      today = datetime.date(datetime.now())
      gt_date = today - timedelta(days=30*int(months))
      self.gt_date = gt_date
  
  if request_type == 'requester':
      query_set = query_set.filter(request_user__request_status=2, request_user__project_to_user=request.user)
      if months:
          query_set = query_set.filter(request_user__created_date__date__gt=gt_date)
  elif request_type == 'connector':
      query_set = query_set.filter(connect_from_user__to_user=request.user)
      if months:
          query_set = query_set.filter(connect_from_user__created_date__date__gt=gt_date)
  elif request_type == 'both':
      request_query_set = query_set.filter(request_user__request_status=2, request_user__project_to_user=request.user)
      connect_query_set = query_set.filter(connect_from_user__to_user=request.user)
      if months:
          request_query_set = request_query_set.filter(request_user__created_date__date__gt=gt_date)
          connect_query_set = connect_query_set.filter(connect_from_user__created_date__date__gt=gt_date)
      query_set = request_query_set | connect_query_set
  </code></pre>
  <p>Everything was working fine but the condition <em>months=5, request_type='both'</em> is causing the Postgres to take so many resources (100% CPU for more than 5 minutes)</p>
  <p>The below code section is causing this issue</p>
  <pre><code>request_query_set = request_query_set.filter(request_user__created_date__date__gt=gt_date)
  connect_query_set = connect_query_set.filter(connect_from_user__created_date__date__gt=gt_date)
  </code></pre>
  <p>Is there any other method that I can use to get the query that I need. I just need to filter according to the months of the created date from both models.</p>