Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sXY5k-004l0R-8L for pgsql-general@arkaria.postgresql.org; Sat, 27 Jul 2024 03:27:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sXY5h-002GTo-Ec for pgsql-general@arkaria.postgresql.org; Sat, 27 Jul 2024 03:27:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sXY5h-002GTf-0S for pgsql-general@lists.postgresql.org; Sat, 27 Jul 2024 03:27:29 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sXY5b-001gHB-0M for pgsql-general@lists.postgresql.org; Sat, 27 Jul 2024 03:27:28 +0000 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-52f04b3cb33so4145219e87.0 for ; Fri, 26 Jul 2024 20:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722050841; x=1722655641; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YGkWeF/+PKlc3es+pUUuY8SQEzgTuzGo0PGAopwNU7A=; b=nD1fKPmbpfTKNzc+XJuX1bMINAk8HbZrCRyuoQIPhJDUn4UwtNwPadRrvpMZ1JKAeE QhcbgOpU6ZQmrgd7CkgoIUKTF8bJt26Vq4PhpnseEp9X6IRQOJdtX+lk73Q1R6Hs3VCF b+m7bNieGIcBUfdbE/3hG03ksBHBXlnsCYUdiQblLQDwsxFhnQdGaphTOpBCpw4+MHl6 wndugcUvBajRLEZ/dIo1HV93yX3Ywq73Bg36OJLPPwiBSliIN3APR73J61r6FarePMQZ pYYjwiKYmdTw2oUUaBVYCx8wtu0x+srnGdvWlohOlWGzQLjNl8rlX04+95rsH+4qiWnH NQDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722050841; x=1722655641; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YGkWeF/+PKlc3es+pUUuY8SQEzgTuzGo0PGAopwNU7A=; b=NtJ7ieHLvJGmqb87qqmRKl+oYK2RwFPhiPom7vvmHUjN3PwSPQvX0QOvyrRMyARYcl akW3JGXIJeOlzGA18TgV9F/FrE6cTtKbSjCppcQ8Gur+LjHrYNDmwndhRTCcQkifwOjR lPvo4xSiHMgvMGSlK3jTGi88XF8CHPl+su6CVGdF1xT/xnMXSWp+S21YXGUFl2Rghmc4 YyU/8js0ohaAjLHxMSENvsxbgsAjW6aDUvm8IlLxyLiwk8ZNT2jlyxY/yFoui/ZYjQyd pzB40Dpfk5Dqfpufe8rKlmWmiizvQXRkjSiLmoKrT5htlTZpM+UDIHh+Ag7Ca6siIG1C ocjw== X-Forwarded-Encrypted: i=1; AJvYcCXyg2DR/oxb1hOOnWUdnEpfQGKqpJuVwRC5WoQVSQxCsc2k0V1g2bq3kWTgjJ/2nXJoCmWTzWO2kKr8GirLN8V5M7cYHy1mi6en446Tb+xbBKPW X-Gm-Message-State: AOJu0YwcKFln0TtCenbUnPHOYYuToDYY6hD+pedvE3tQHStue909dMIs LZ4G9JLMUJM37t+CFxrp/oSMEP0VZO5C8nNkglkuY3bgpWkVDrYZ7BY/erl/RQXppFXQ1EIdv/7 EzSr5/pTHebeG8aGZ5V0VYHxCLbM= X-Google-Smtp-Source: AGHT+IF6z+YLBsOMvCMCq9Z8JwzSo8N8btqbfVbgmsDKyZs8ERe11JlYXqBamgglS207rBILNLGCFXP3lQAryrqLwpc= X-Received: by 2002:ac2:51c4:0:b0:52e:9cc7:4462 with SMTP id 2adb3069b0e04-5309b2693fbmr1558600e87.11.1722050840314; Fri, 26 Jul 2024 20:27:20 -0700 (PDT) MIME-Version: 1.0 References: <431223779.107307.1721971823963.ref@mail.yahoo.com> <431223779.107307.1721971823963@mail.yahoo.com> In-Reply-To: From: David Rowley Date: Sat, 27 Jul 2024 15:27:08 +1200 Message-ID: Subject: Re: Slow performance To: Francisco Olarte Cc: "sivapostgres@yahoo.com" , Postgresql General Group Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 26 Jul 2024 at 19:55, Francisco Olarte wrote: > " -> Index Scan using > ""cl_student_semester_subject_IX3"" on cl_student_semester_subject p > (cost=0.55..8.57 rows=1 width=60) (actual time=0.033..55.702 > rows=41764 loops=1)" > " Index Cond: (((companycode)::text = '100'::text) > AND ((examheaderfk)::text = > 'BA80952CFF8F4E1C3F9F44B62ED9BF37'::text))" > > Not an explain expert, but if i read correctly an index scan expecting > 1 row recovers 41674, which hints at bad statistics ( or skewed data > distribution and bad luck ) You have correctly identified the reason the poor plan was chosen. If that row estimate was anything higher than 1, that plan wouldn't be picked. If ANALYZE cl_student_semester_subject; does not fix the issue, then increasing the statistics targets with something like: alter table cl_student_semester_subject alter column companycode set (default_statistics_target = 1000); alter table cl_student_semester_subject alter column examheaderfk set (default_statistics_target = 1000); analyze cl_student_semester_subject; (Warning, additional statistics targets can slow down planning a little) or if that does not help and there's some correlation between those columns and/or the values in question, then maybe the following might help get a more accurate estimate: create statistics on companycode, examheaderfk from cl_student_semester_subject; analyze cl_student_semester_subject; David