From nobody@FreeBSD.org  Wed Dec 23 16:16:49 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 8CB311065670
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 23 Dec 2009 16:16:49 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 7CC0A8FC23
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 23 Dec 2009 16:16:49 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id nBNGGm5P012675
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 23 Dec 2009 16:16:48 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id nBNGGmYI012674;
	Wed, 23 Dec 2009 16:16:48 GMT
	(envelope-from nobody)
Message-Id: <200912231616.nBNGGmYI012674@www.freebsd.org>
Date: Wed, 23 Dec 2009 16:16:48 GMT
From: Stepan Koltsov <yozh@mx1.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sort -k 3,1g is very slow
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         141920
>Category:       bin
>Synopsis:       sort(1): sort -k 3,1g is very slow
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Dec 23 16:20:01 UTC 2009
>Closed-Date:    
>Last-Modified:  Thu Dec 24 13:09:39 UTC 2009
>Originator:     Stepan Koltsov
>Release:        7.2
>Organization:
>Environment:
7.2-STABLE amd64
>Description:
sort -k 3,1g is very slow.
>How-To-Repeat:
1. Generate a file:

for i in {1..10000}; do echo 1261583423 a a; done > txt

(10000 lines "1261583423 a a")

2. Run sort with simpler options:

time cat txt | sort -k 3,1 > /dev/null
time cat txt | sort -k 3,1n > /dev/null
time cat txt | sort -k 1g > /dev/null
time cat txt | sort -k 2,1g > /dev/null

All these commands work fast (in 0.03s).

3. Run sort wih -k 3,1g:

time cat txt | sort -k 3,1g > /dev/null

It takes 4 seconds. It is too long.
>Fix:


>Release-Note:
>Audit-Trail:

From: Lowell Gilbert <freebsd-bugs-local@be-well.ilk.org>
To: Stepan Koltsov <yozh@mx1.ru>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: misc/141920: sort -k 3,1g is very slow
Date: Wed, 23 Dec 2009 14:05:52 -0500

 Stepan Koltsov <yozh@mx1.ru> writes:
 
 > 3. Run sort wih -k 3,1g:
 >
 > time cat txt | sort -k 3,1g > /dev/null
 >
 > It takes 4 seconds. It is too long.
 
 Does that actually mean anything useful?
 It's fields 3 to 1, right?

From: Stepan Koltsov <yozh@mx1.ru>
To: Lowell Gilbert <freebsd-bugs-local@be-well.ilk.org>
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: misc/141920: sort -k 3,1g is very slow
Date: Wed, 23 Dec 2009 22:42:54 +0300

 On Wed, Dec 23, 2009 at 22:05, Lowell Gilbert
 <freebsd-bugs-local@be-well.ilk.org> wrote:
 > Stepan Koltsov <yozh@mx1.ru> writes:
 >
 >> 3. Run sort wih -k 3,1g:
 >>
 >> time cat txt | sort -k 3,1g > /dev/null
 >>
 >> It takes 4 seconds. It is too long.
 >
 > Does that actually mean anything useful?
 > It's fields 3 to 1, right?
 
 You are right. I thought it means sort by 1st, then by 3rd.
 
 So, I think warning should be printed (or error).
 
 S.
>Unformatted:
