Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icG6R-0007g8-Sc for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Dec 2019 21:53:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1icG6Q-0003fx-Gd for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Dec 2019 21:53:02 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icG6Q-0003fq-3r for pgsql-hackers@lists.postgresql.org; Tue, 03 Dec 2019 21:53:02 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icG6M-0008OK-Mn for pgsql-hackers@postgresql.org; Tue, 03 Dec 2019 21:53:01 +0000 Received: by mail-qk1-x742.google.com with SMTP id f5so5043188qkm.13 for ; Tue, 03 Dec 2019 13:52:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=mkss5iKgpva3zna7Cmt1wkumXZPXvOeHQ8wSILRcaaE=; b=Z9A9Sw+Pd0JlgLk3bKZHsoJFGZ40N5vvmQ7b9fmSEKBB9P5etKbTUMnP4jf5Ba/pB5 vbjgxre8o5biJRRL+x4zhAzewbsUgYeMa/0BOEk+Y0YcuzRcWtdDnHYUBaV2Fg9S7Twi fuSPzfareEUmw3yTPfwA8Cm0yr5IQl4JDnK412y1cvJgetGvsUKAQkqBQYdABq1vxH/n Hryj0vYz7Av1rJxCS5HR1/2HROFx11bBBFR8CmqjMdQkkp3NyfXETgCPz6tzh5y3jOdI cXOu0Xcuj/wbDFzEKfjMMi4kxbKgZCf1oUDyk14TnYd94jDnKuGwDoldhpEo0SBW1fDA 3EPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=mkss5iKgpva3zna7Cmt1wkumXZPXvOeHQ8wSILRcaaE=; b=h59t3QtNchMtJ6za9Wxp1ub7rRec0+iYiAS/NZ2bYSYwPjOwToPYRBnM9kQrUHrwM9 HHk4XjIfKjxaLGrQZvE65jSAxmYb4eGCv5kS/KwH3YUX9SPmNxeFeTETpqyzcnQGu6FL s8PPtdaLunQ2CsetcUjw40J66+9wdKayiXZJldgzirqirxPtD/zo+aMFmZgrKHP506QJ rqXuO5mRFS7xMMS1XY2YqLtKa5T7VopzGRiob0yuDnTXaXn/9a/GExJHZvLhmq6W1+4t htMJCIQ9Gb3N6O4xt+hqD97eD9Ks/5LcURxUR0EQPTILeS1f620SpWWzsk0YjRtniWQu fe2A== X-Gm-Message-State: APjAAAWfzBiUG9lY5esTXR6JLYZeD+CCuzic32XuEvVFCtggA9fL92AW tQFNQrWslTwq9+Mk9b171irNbQ== X-Google-Smtp-Source: APXvYqx4QYmT8x8s/OShn9GwKyvlnz763ugnZ25quTOyI5jrbu3Wu8vY4BIcRqTysw9mxgvRsKEHuQ== X-Received: by 2002:a37:9b46:: with SMTP id d67mr7343187qke.77.1575409976955; Tue, 03 Dec 2019 13:52:56 -0800 (PST) Received: from nimloth.alvh.no-ip.org ([179.56.51.67]) by smtp.gmail.com with ESMTPSA id s20sm2443891qkj.100.2019.12.03.13.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2019 13:52:56 -0800 (PST) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 663B53007F7; Tue, 3 Dec 2019 18:17:39 -0300 (-03) Date: Tue, 3 Dec 2019 18:17:39 -0300 From: Alvaro Herrera To: Andres Freund Cc: Alexey Bashtanov , Peter Eisentraut , PostgreSQL Hackers Subject: Re: log bind parameter values on error Message-ID: <20191203211739.GA12872@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191203152240.GA21110@alvherre.pgsql> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-Dec-03, Alvaro Herrera wrote: > Now, I have to say that this doesn't make me terribly happy, because I > would like the additional ability to limit the printed values to N > bytes. This means the new function would have to have an additional > argument to indicate the maximum length (pass 0 to print all args > whole) ... and the logic then because more involved because we need > logic to stop printing early. So after actually writing this, it seems that it's better to have a separate path for this; otherwise you need to scan the whole input string (strchr or friends), which might be long. I tried to see how to make strnlen() work for us, but I found no simple way to print the "..." at the end. So this just runs once per char. I think that's okay, since the intended usage is to print a few dozen bytes, like ExecBuildSlotValueDescription does (64 bytes is what all its callers do). Another point: this implementation is not strict about how many input characters it prints. It counts up to maxlen *output* characters, which means if it duplicates a ', that's one less input char printed. (Given the usage of this function, this seems a feature rather than a bug. The first implementation did the opposite, and on the whole it seemed worse.) If anyone can suggest a smarter implementation, I'm all ears. (Maybe do strnlen(maxlen), then count strnlen(1) starting at that point -- so if that returns >=1, print the "..."?) -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services